python中制作程序界面,如何在python中制作命令行界面或解释器

guys. I have seen some CLI questions here, but I still want to ask this question for more detailed answers.

I have already developed class1.py, class2.py, etc. with functions implemented inside each class. e.g. Operator.py has add, minus,time, devide functions. how can I build a command line interface for these classes?

also for this CLI, is it a infinite loop inside the main() for interaction?

And how can the CLI give some feedback such as, suggesting the user for the next operation or to input right command or type --help and check all the available commands. like the Bash shells.

also it seems there is optparse module from python. is there some good, complete, or high quality samples showing how a CLI is built? I would like to take this chance to learn how to write a CLI program.

what i want is: I have already developed several classes, and also a GUI to call the methods from these classes. Now i want to have a CLI, like the GUI, to use these classes. e.g. I have classes like CDContainer (with method like addCD, removeCD, etc), CD (with method like play, stop, pause), and I have a GUI that could be interacted. Now I want to have a CLI, which under the bash, I could run this CLI and call createCDContainer, addCD, removeCD commands.

If I use cmd,

class CDContainerCLI(cmd.Cmd):

def do_CDContainer(self, line):

print "create CD container"

def do_addcd(self, line):

print "add cd into the container"

how do I add some options here? e.g., I want to addcd --track 3 --cdname thriller

I think "--track 3 --cdname thriller" they are the 4 arguments for the addcd function. how to implement that?

解决方案

Derive from cmd.Cmd, overriding the various methods as necessary.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值