Skip to main content

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', 'impython'], stdin=PIPE) as f:
    f.stdin.write('print("hello world")'.encode())
    f.stdin.write('$exec'.encode())
    f.stdin.write('a = 1 / 0'.encode())
    f.stdin.write('$exec'.encode())
    f.stdin.write('$exit'.encode())

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

impython-0.1.1.tar.gz (2.8 kB view hashes)

Uploaded Source

Built Distribution

impython-0.1.1-py3.8.egg (5.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page