使用 Python 的自定义(交互式)shell [英] Custom (interactive) shell with Python

查看:48
本文介绍了使用 Python 的自定义(交互式)shell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试为我编写的自定义脚本制作一些类似 shell 的小实用程序,以便我可以轻松地使用它(它相当简单,因此交互式 shell 将是完美的).

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).

你有关于如何在 Python 中创建 shell 的任何资源吗?我在谷歌上搜索了一段时间,但我只能找到有关 IDLE 和类似 Python 解释器的信息.但我更想知道如何编写一个完全自定义和基于命令行的 shell.

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.

我的方法是为命令挂钩 stdin/out,但鉴于 Python 库提供了如此多的出色实用程序,如果没有更好的方法,我想确保存在.

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.

推荐答案

cmd 标准库中的模块可能是一个开始——如果您在使用它时遇到任何问题,请发布更具体的问题(最好用一些玩具示例来展示您要实现的目标以及您得到的结果!).

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!).

这篇关于使用 Python 的自定义(交互式)shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆