impython is a python interpreter that accepts pipe stdin inputs and recognizes some magic commands.
Project description
I'm Python
What's impython
?
impython
is absolutely an interpreter for python based on the function exec
. Besides, impython
recognizes some magic commands.
Why impython
?
If any program is intended to call python and to get its results (either in form of returning values or making changes in OS), the most convenient method is to start a process of python and pass python commands to python interpreter via pipe. However, the way python interacts with pipe is wired. Python will NOT execute any commands until you close the stdin. But once you close the stdin, NO other commands can you write into stdin any more.
By using python -m impython
, now all issues are solved. Try this:
from subprocess import Popen, PIPE
with Popen(['python', '-m', 'impythpon'], stdin=PIPE, stdout=PIPE, stderr=PIPE) as f:
f.stdin.write('print("hello world")')
print(f.stdout.read())
# hello world
f.stdin.write('a = 1 / 0')
print(f.stderr.read())
How to impython
?
An easy way is
python -m pip install --upgrade pip
python -m pip install impython
A hard way is
git clone https://gitee.com/junruoyu-zheng/impython.git
cd impython
python setup.py build
python setup.py install
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.