0

I've got a python script for automating a task. But every time I run it, it asks for input to provide. So for instance when I run the following command:

$ python icecream.py
Which flavor do you want to choose?
1. Blueberry
2. Vanilla

What I want to know is that how can I provide pre-input to the script if I like the vanilla flavor. Can I use a flag like python icecream.py -1. I'm a beginner at this, so please tolerate if I'm doing anything wrong.

uchiha
  • 81
  • 6
  • 1
    shot answer: [argparse](https://docs.python.org/3/library/argparse.html) – Brown Bear Aug 09 '21 at 18:56
  • Interesting setup you got there. If you use it for automation it might be more useful to remove the input from your function and directly call the script using an argument from shell. They explain it well here: https://stackoverflow.com/questions/14155669/call-python-script-from-bash-with-argument – Anton van der Wel Aug 09 '21 at 18:56
  • 2
    this depends on your OS, of course, but in Unixy bash-like shells, pipe the input `printf "1\n" | python icecream.py` but it's probably better to create the script to accept arguments, not using `input()` – juanpa.arrivillaga Aug 09 '21 at 18:58
  • Thanks @juanpa.arrivillaga. It did the trick for me. – uchiha Aug 10 '21 at 06:15

0 Answers0