Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for accepting batch inputs #4

Open
LavanyaBurlagadda opened this issue Apr 27, 2023 · 1 comment
Open

Support for accepting batch inputs #4

LavanyaBurlagadda opened this issue Apr 27, 2023 · 1 comment

Comments

@LavanyaBurlagadda
Copy link

Is there any direct way to provide batch inputs while running the code without any waiting

@alexmojaki
Copy link
Owner

Just provide a callback that reads a line directly from the batch input.

from python_runner import PatchedStdinRunner

batch_input = "hello\nworld"
input_lines = batch_input.splitlines()

events = []


def callback(event_type, data):
    events.append((event_type, data))
    if event_type == "input":
        return input_lines.pop(0)


runner = PatchedStdinRunner(callback=callback)
runner.run("print(1, input(), 2, input())")
for event in events:
    print(event)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants