简体   繁体   English

Python cmd2模块发送命令

[英]Python cmd2 module send commands

I have implemented a custom command line with python cmd2 module. 我已经使用python cmd2模块实现了自定义命令行。

from cmd2 import Cmd
class CliApp(Cmd):
      .....

Now I also need to send commands to my custom command line from other python project. 现在,我还需要从其他python项目向我的自定义命令行发送命令。 I tried: 我试过了:

send = CliApp().send
print send('hello')

Which gives the error: 给出错误:

AttributeError: Cmd instance has no attribute 'send' AttributeError:Cmd实例没有属性“发送”

I have also tried the original example from: 我也尝试过以下原始示例:

cmd2 - the-send-method - but it gives the same error. cmd2-发送方法 -但给出相同的错误。

The python cmd2 module which was originally developed by Catherine Devlin around 2008 and has a project page on GitHub under python-cmd2/cmd2 appears to be a completely separate entity from cmd2 module developed around the same time frame by Michele Simionato . python cmd2模块最初由Catherine Devlin于2008年左右开发,并在GitHub上的python-cmd2 / cmd2下有一个项目页面,似乎与Michele Simionato在同一时间框架内开发的cmd2模块完全独立。

You can read the documentation for the cmd2 module which you can install from PyPI at cmd2.rtfd.io and note that it does NOT have a send method. 您可以在cmd2.rtfd.io上阅读可从PyPI安装的cmd2模块文档,并注意它没有send方法。

To accomplish what you want, I would suggest looking at the cmd2 source code for the onecmd_plus_hooks method and at the cmd2 unit tests which call this method via the run_cmd helper in conftest.py. 为了完成您想要的工作,我建议查看onecmd_plus_hooks方法的cmd2源代码以及通过conftest.py中的run_cmd帮助程序调用此方法的cmd2单元测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM