Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python file.py从命令行运行类?_Python_Linux_Class_Terminal - Fatal编程技术网

如何使用python file.py从命令行运行类?

如何使用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('.......')

当我运行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)

# 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()