Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Support for providing input to programs #54

Open
anandology opened this issue Feb 26, 2022 · 0 comments
Open

Support for providing input to programs #54

anandology opened this issue Feb 26, 2022 · 0 comments
Assignees

Comments

@anandology
Copy link
Contributor

Some examples in mypy-primer uses input and that doesn't work currently.

Proposal

Make it possible to specify stdin and run the program with that as stdin.

Suggested format is:

<span id="data-greet" data-stdin='"foo\n45"'></span>

```{.python .example .hijack-input #greet}
def greet(name):
    print(f"Hello, {name}!")

if __name__ == '__main__':
    name = input("Enter your name: ")
    age = input("Enter your age: ")

    greet(name)
    print(f"You will be {age + 1} years old next year.")
```

Please not that the input is specified as JSON.

PoC

inputs = iter(["foo", "45"])

def new_input(prompt):
    print(prompt, end="")
    x = next(inputs)
    print(x)
    return x

input = new_input

def greet(name):
    print(f"Hello, {name}!")

if __name__ == '__main__':
    name = input("Enter your name: ")
    age = input("Enter your age: ")

    greet(name)
    print(f"You will be {age + 1} years old next year.")
@anandology anandology self-assigned this Feb 26, 2022
anandology added a commit to fossunited/falcon that referenced this issue Feb 28, 2022
anandology added a commit to anandology/monschool-website that referenced this issue Feb 28, 2022
anandology added a commit to anandology/monschool-website that referenced this issue Feb 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant