Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom (interactive) shell with Python [closed]

Tags:

I'm currently trying to make some small shell-like utility for a custom script I wrote, so I can easily work with it (it's rather simple, so an interactive shell would be perfect).

Do you have any resources for me on how to create a shell in Python? I spent googling for a while, but all I could find was information about IDLE and similar Python interpreters. But I would rather want to know how to write a completely custom and command line based shell.

My approach would be hooking the stdin/out for commands, but given that the Python library offers so many great utilities, I want to make sure there if there is no better way.

like image 800
poke Avatar asked Dec 21 '09 00:12

poke


People also ask

How do I open the interactive shell in Python?

To run the Python Shell, open the command prompt or power shell on Windows and terminal window on mac, write python and press enter. A Python Prompt comprising of three greater-than symbols >>> appears, as shown below. Now, you can enter a single statement and get the result.

Why is Python shell called as interactive shell?

The Python interpreter can be used from an interactive shell. The interactive shell is also interactive in the way that it stands between the commands or actions and their execution. In other words, the shell waits for commands from the user, which it executes and returns the result of the execution.

Can shell be used interactively?

An interactive shell is defined as the shell that simply takes commands as input on tty from the user and acknowledges the output to the user. This shell also reads startup files that occurred during activation and displays a prompt. It also enables job control by default.


2 Answers

The cmd module in the standard library could be a start -- if you have any trouble using it, please post more specific questions (ideally with some toy example showing what you're trying to achieve and what you're getting instead!).

like image 54
Alex Martelli Avatar answered Oct 06 '22 04:10

Alex Martelli


You might have a look at pyparsing. It is definitely only about lexing and parsing, but that's definitely the hardest part of the problem.

like image 22
teepark Avatar answered Oct 06 '22 05:10

teepark