Importing Python module from Bash
use a subroutine instead of alias
callmyprogram(){
python -i -c "import time;print time.localtime()"
}
callmyprogram
An easy way to do this is with the "code" module:
python -c "import code; code.interact(local=locals())"
This will drop you into an interactive shell when code.interact() is called. The local
keyword argument to interact
is used to prepopulate the default namespace for the interpreter that gets created; we'll use locals()
, which is a builtin function that returns the local namespace as a dictionary.
Your command would look something like this:
python -c "import mymodule, code; code.interact(local=locals())"
which drops you into an interpreter that has the correct environment.
Example:
python -c "import time ; print 'waiting 2 sec.'; time.sleep(2); print 'finished' "