Strip and execute interactive Python string
Project description
Strip Interactive Python String
Have you ever come across an online tutorial that shows interactive Python code like this:
>>> import numpy as np
>>> print(np.array([1,2,3]))
array([1, 2, 3])
and wished to run only the inputs like below?
import numpy as np
print(np.array([1,2,3]))
That is when strip-interactive comes in handy.
Usage
To use strip-interactive, simply add the code you want to run to run_interactive
method.
from strip_interactive import run_interactive
code = """
>>> import numpy as np
>>> print(np.array([1,2,3]))
array([1, 2, 3])
"""
outputs = run_interactive(code)
Output:
[1 2 3]
You can also get the clean code (without inputs and >>>
) using get_clean_code
method.
from strip_interactive import get_clean_code
code = """
>>> import numpy as np
>>> print(np.array([1,2,3]))
array([1, 2, 3])
"""
inputs = get_clean_code(code)
print(inputs)
Output:
import numpy as np
print(np.array([1,2,3]))
Installation
pip install strip-interactive
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
strip-interactive-0.1.4.tar.gz
(10.5 kB
view hashes)
Built Distribution
Close
Hashes for strip_interactive-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb7883c3766330f87fce2df9a2d9919d1d8b2991e2054c52143a6b500be8d7e7 |
|
MD5 | f14b9d61a0ec32b82f373ea6d9783739 |
|
BLAKE2b-256 | 25a99f4b1eab1488f854f5b1c3ee73a71618ed1f63daaf42a5577423f624b035 |