如何与python文件交互';从命令行中选择对象方法(放置输入、更改数据和获取输出)?
假设这是我的python程序如何与python文件交互';从命令行中选择对象方法(放置输入、更改数据和获取输出)?,python,shell,command-line-interface,Python,Shell,Command Line Interface,假设这是我的python程序 from __future__ import absolute_import, division, print_function class Concat_Class(): def __init__(self, cache=False): self.cats = [] def GET_Answers(self, questionList, context): for question in questionLis
from __future__ import absolute_import, division, print_function
class Concat_Class():
def __init__(self, cache=False):
self.cats = []
def GET_Answers(self, questionList, context):
for question in questionList:
self.cats.append(question + context )
return self.answers
class Interface_Class():
def __init__(self):
self.questionList = []
self.answers = []
self.catObj = Concat_Class()
def POST_Question(self, question):
self.questionList.append(question)
def PUT_Question(self, index, question):
self.questionList[index] = question
def PUT_Conext(self, context):
self.context = context
def GET_Answers(self):
answers = self.modelObj.GET_Answers(self.questionList, self.context)
print(answers)
if __name__ == "__main__":
interface_Object = Interface_Class()
我将其保存到名为testProgram.py的文件中
我将如何与接口\u对象
交互,调用其方法,向这些方法传递参数,等等
编辑:
我不想一开始就做一次互动。我需要不断更新这些值 用
python-i testProgram.py
调用它,在脚本完成执行后,您将留在python REPL中。然后,您可以键入诸如interface\u Object.GET\u Answers()
之类的内容以交互方式进行尝试。如果您想将参数传递到从命令行运行的python脚本中,我认为argparse是您想要的模块:虽然文档有点不透明,但我会寻找其他材料来提供帮助。