我有一个python文件test1.py,它有以下代码(例如) -
class Testing(BaseTestRemote):
def collect_logs(self):
def delete_logs(self):
那么如何从命令行只运行collect_logs()(在类Testing中),请举例说明一下?
答案 0 :(得分:1)
让我们创建一个名为file.py
的文件,其中包含以下内容:
class test(object):
def __init__(self):
return
def square(self, x):
return x*x
def cube(self, x):
return x*x*x
从包含file.py
的目录运行命令行并执行以下操作:
~$ python
Python 2.7.11+ (default, Apr 17 2016, 14:00:29)
[GCC 5.3.1 20160413] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import file
>>> obj = file.test()
>>> obj.square(2)
4
>>> obj.cube(4)
64
>>> from file import test
>>> test().square(2)
4
>>> test().square(4)
16
>>> x = test()
>>> x.square(2)
4
>>> x.square(4)
16
>>>