如何使用python file.py从命令行运行类?
当我运行python filename.py时,它不会提示输入或打印输出。要运行类Base1(),我必须运行什么命令如何使用python file.py从命令行运行类?,python,linux,class,terminal,Python,Linux,Class,Terminal,当我运行python filename.py时,它不会提示输入或打印输出。要运行类Base1(),我必须运行什么命令 程序必须包含一些顶层语句(即不缩进),当程序在命令行上运行时将执行这些语句 class Base(TestCase): def setUp(self): #prompts for inpt ...... class Base1(Base): def base1(self): print('.......')
程序必须包含一些顶层语句(即不缩进),当程序在命令行上运行时将执行这些语句
class Base(TestCase):
def setUp(self):
#prompts for inpt
......
class Base1(Base):
def base1(self):
print('.......')
return x
def base2(self):
output = Base1.base1(self)
print(output)
# These commands will be executed when "python filename.py" is run from a shell
foo = Base1()
foo.base1()
....
qwrrty建议的方法会起作用,但我建议将其放在python中由
def main():
foo = Base1()
foo.base1()
if __name__ == "__main__":
main()
def main():
foo = Base1()
foo.base1()
if __name__ == "__main__":
main()