Makes scripts feel like functions.
Project description
callscript
Want to add a GUI, CLI, or simply test your script, but you don't want to modify your code? Call a script as though it were a function!
Installation
pip install callscript
Usage:
If you label your script with the "input" or "output" comments, callscript
can call it!
# examples/script.py
x = 3 # input
y = 5 # input
z = x + y # output
Then from your other code, you can call it with the callscript()
function:
>>> from callscript import callscript
>>> callscript('examples/script.py', x=10, y=20)
{'z': 30}
Want to change your variable names? You can do that, too!
# examples/script2.py
x = 3 # input:FirstWeek
y = 5 # input:SecondWeek
z = x + y # output:sum
>>> callscript('examples/script2.py', FirstWeek=10, SecondWeek=20)
{'sum': 30}
Want some lines to be ignored when being called by callscript()
? Use the # ignore
tag!
# examples/script3.py
x = 3 # input
y = 5 # input
input('What is your name?') # ignore
z = x + y # output
z = 100000 # ignore
>>> callscript('examples/script3.py', x=10, y=20)
{'z': 30}
callscript()
will use the original values of the inputs in the script as defaults.
# examples/script4.py
name = 'Nick' # input
greeting = 'Hello, ' # input
msg = greeting + name # output
>>> callscript('examples/script4.py', name='Emma')
{'msg': 'Hello, Emma'}
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.
Source Distribution
callscript-0.5.1.tar.gz
(6.3 kB
view hashes)
Built Distribution
Close
Hashes for callscript-0.5.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d32b87272f7715c9ae6e5deb925e1e9c3db9f08f84117b4fc5368a54a1db6e45 |
|
MD5 | 44319361c87f142ea1a0a730fc612be1 |
|
BLAKE2b-256 | d377ce3276fdb8db8c32d5168d0cf68b01c934dd95dffbb19124e9180bd4a86f |