我对python中的CMD模块有问题。我需要能够在do语句之后添加值,例如:
def do_test(self,x,y):
calculate = x * y
print (calculate)
我试着阅读python网站上关于cmd.py的原始文档,但作为初学者,我很难理解其中的任何一个
我也试着在github、stackoverflow、reddit和youtube上寻找和我想做的一样的项目。但似乎cmd模块更多地用于不获取任何新值的静态函数
import cmd
import sys
class TestCMDcmd.Cmd):
intro = 'Welcome to this simple command prompt'
prompt = ">>"
# i want to do something like this using the cmd library
def do_test(self,x,y):
print (x*y)
# psudo code:
'''
def addnumbers (x,y):
print (x,y)
command = input("addnumbers (4,2)")
if command == add numbers + # some kind of way of writing for example 2 and 4 :
print (addnumbers(inputvalue1 and input value2))
'''
def do_quit(self,arg):
"""Exit command prompt"""
return True
if __name__ == '__main__':
TestCMDcmd().cmdloop()
目前没有回答
相关问题 更多 >
编程相关推荐