扩展 Python 交互式 shell
我想扩展Python交互式shell以允许执行非Python特定的语句或命令。这个想法是,如果您在提示符下键入一些会引发 NameError
的内容,则可以解析您键入的内容以查找已知的外部命令,并且只有无法找到外部命令时,才会引发 NameError
。
我不太确定从哪里开始,我尝试在 try: / except NameError
中调用 code.InteractiveConsole().interact()
但那
不起作用阅读 cmd 模块的文档,但我看起来它的设计只是为了调用外部命令并忽略 python 语句。
目标是一个简单的(适用于非常小的、无 GUI 的系统)命令 shell,可以使用 python(而不是 sh)编写脚本。
我应该在哪里寻找?纯 Python 解决方案是理想的。
I'd like to extend the Python interactive shell to allow execution of non-python specific statements or commands. The idea being, if you type something on the prompt that would raise a NameError
what you typed could be parsed for known external commands, and only it failing to find an external command, raise the NameError
.
I'm not quite sure where to start, I tried calling code.InteractiveConsole().interact()
inside a try: / except NameError
but that didn't work
I read the documentation for the cmd
module, but I looks like its designed JUST for calling external commands and ignores python statements.
The goal is a simple (its for a very small, GUI-less system) command shell that can be scripted with python (rather than sh)
Where should I be looking? A pure Python solution is ideal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个文档: http://ipython.scipy.org/ doc/manual/html/interactive/tutorial.html
当使用 python 作为 shell 替代品时,我认为已经涵盖了很多内容。
Have a look at this documentation: http://ipython.scipy.org/doc/manual/html/interactive/tutorial.html
When it becomes using python as a shell replacement, I think are pretty much covered.