metakirby5 / codi.vim

:notebook_with_decorative_cover: The interactive scratchpad for hackers.
MIT License
3k stars 83 forks source link

How to feed to STDIN of the codi interpreter? #124

Closed pvonmoradi closed 4 years ago

pvonmoradi commented 4 years ago

Is there a way to pass some data to STDIN of the interpreter that codi is running?
For example suppose the python code is like x, y = [int(x) for x in input().split(' ')]. The input() function fetches the stdin buffer.
How can I make it so that "5 10" is automatically passed into the stdin of the python interpretor instance?
I can do it in bash like this way: python mycode.py <<< $'5 10'
Thanks

metakirby5 commented 4 years ago

What's your objective in using Codi to achieve this? Sure, you could change the configuration for your interpreter, but I'm not sure how it helps any more than doing python mycode.py <<< $'5 10' as you mentioned.

pvonmoradi commented 4 years ago

I thought it would be cool if I could see the value of variables while coding. Consider the following code:

x = 2
y = 4
z = x + y

z is immediately shown to be 6. But in this code:

x = int(input())
y = 4
z = x + y

z's value is not immediately visible. I want the interpreter instance running on codi accept "2" in its STDIN.

metakirby5 commented 4 years ago

Ah, understood! Codi operates directly off stdout/stdin, so achieving what you described will not directly be possible. Instead, maybe you could load your desired input from a file? For example:

with open('input.txt') as f:
  x = int(f.read().strip())
y = 4
z = x + y