![](/img/trans.png)
[英]VS Code Terminal Autocompletion does not working with python interactive shell
[英]Custom interactive terminal (CLI) with autocompletion on classes and objects
我想在程序中有一個類似於IPython的交互式提示。
我想擁有的功能是:
到目前為止,我一直在玩readline
有自動完成回調函數和魔術方法如__dir__
, __doc__
或__dict__
。
我確定我可以實現這樣的解決方案,但是我正在尋找一個可以為我完成工作的現有模塊。
以我的想法,我想這樣使用它:
class Foo:
def Say(self):
return "The answer is 42"
foo = Foo()
cli = Cli() # The terminal interface I want to have
cli.RegisterObject(foo, showAttributes = True, showProtected = True)
cli.AddCommand('exit', exit)
cli.Start(defaultPrompt = ">")
一位朋友建議我使用IPython而不是自定義解決方案。 不幸的是,對於我的應用程序來說,IPython太開放了,新手肯定會感到困惑。 我不希望最終用戶可以訪問所有內容。
最后,我們將得到以下內容:
$ ./cli.py
>foo.<tab>
Say
>foo.Say()
The answer is 42
>bar.AreYouHere()
Unknown command!
>exit
一些相關的問題是:
不幸的是,答案建議使用不是我所需要的cmd模塊。
嵌入IPython 。 比制作類似IPython的東西要好,因為它是IPython。
至少,啟動IPython會話涉及:
from IPython import embed
embed()
IPython參考中提供了許多其他配置選項(包括示例)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.