当我运行 python filename.py 时,它不会提示输入或打印输出。我必须运行什么命令才能运行类 Base1()?
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)
最佳答案
您的程序必须在顶层包含一些语句(即不缩进),这些语句将在您的程序在命令行上运行时执行。
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()
....
关于python - 如何使用 python file.py 从命令行运行类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20531916/