I want to develop a small Python app that interacts with the user via the console/command line. Are there any good libraries I can use to get user input and display the output in a nice-looking way? I tried searching but most of what I found was command-line argument processing, didn't see anything about user interaction in the shell.
It should be crossplatform (Windows and Linux)
The cli package is a framework for making simple, correct command line applications in Python. With cli, you can quickly add standard command line parsing; logging; unit and functional testing; and profiling to your CLI apps.
To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World!
Command Line Applications (aka CLI applications or simply CLIs - for Command Line Interface) are programs that you interact with entirely through your terminal and shell. They have no graphics or visual interface beyond what you see in your terminal after you run the program.
A really excellent library is cmd which is part of the python standard library. It is cross platform Windows, Linux, Mac. You just have to implement one class and it offers so many great features:
If you take the turtle shell example and save it as turtleshell.py and save the below turtle script file as circles.txt
circle 20
circle 50
circle 100
bye
then you could run the turtle script with the following command:
cat circles.txt | ./turtleshell.py
so in the simple example shown in the docs the developer has essentially made a simple mini-language that can be used as an easier interface to to the turtle module making it even easier to introduce programming to kids. The examples above have been taken from the python3 docs because they have included a detailed example in their docs which wasn't there in the 2.7 docs, but cmd is available and fully functional in python 2.3 and later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With