Custom Interactive Shell with AutoComplete

自闭症网瘾萝莉.ら 提交于 2019-12-22 06:54:27

问题


I have been tasked to create an interactive shell to be embedded in python, such that, when called from the command line it will be dropped into that shell. Can anyone recommend me a library that does this?

I would need the ability to create custom words, "actions," so when the user types those words, my program can execute the correct function that I have created. I would also like the ability of auto complete / tab complete on the custom words I created.

Example:

$ python myapplication.py
$ myapp> 
$ myapp> help
   ... prints the help menu
$ myapp> run service blah
   .. service blah runs ...
$ myapp> exit
$ 

回答1:


Try this cmd module. It's designed for that purpose.




回答2:


Python Prompt toolkit is a very good module to use when you want to make a fully featured interactive shell. It comes with all the needed features like :

  • Auto-complete (with visual dropdowns)
  • Command history and search
  • Works cross-platform


来源:https://stackoverflow.com/questions/26226236/custom-interactive-shell-with-autocomplete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!