Python 如何调用函数并更改变量

Python 如何调用函数并更改变量,python,inheritance,variables,Python,Inheritance,Variables,在测试多个响应时,我多次调用函数。我在问我如何在程序的前面调用一个函数,在这个函数中改变一个变量,然后调用它。下面是一段代码 class AbsoluteMove(unittest.TestCase): def Ssh(self): p=pexpect.spawn('ssh user@10.10.10.10') self.command = './ptzpanposition -c 0 -u degx10' p.sendline("

在测试多个响应时,我多次调用函数。我在问我如何在程序的前面调用一个函数,在这个函数中改变一个变量,然后调用它。下面是一段代码

class AbsoluteMove(unittest.TestCase):

     def Ssh(self):

        p=pexpect.spawn('ssh user@10.10.10.10')
        self.command = './ptzpanposition -c 0 -u degx10' 
        p.sendline("cd /bin")
        i=p.expect('user@user-NA:')
        p.sendline(self.command)
        i=p.expect('user@-userNA:')
        self.Value = p.before

class VerifyTilt(AbsoluteMove):

     def runTest(self):

         self.dest.PanTilt._y=2.0

         try:
            result = self.client.service.AbsoluteMove(self.token, self.dest, self.speed)
         except suds.WebFault as detail:
             print detail

         self.command = './ptzpanposition -c 0 -u degx10'
         AbsoluteMove.Ssh(self)

         # Position of the camera verified through Ssh (No decimal point added to the Ssh value)
         self.assertEqual(self.Value, '20')
我想更改AbsoluteMove.Ssh()中的'self.command'变量,然后运行此函数。有人知道怎么做吗


感谢您的帮助

您需要为runTest函数提供一个包装器。注意,我在
runTest

class VerifyTilt(AbsoluteMove):
 def testWrapper(self):
     self.command = './ptzpanposition -c 0 -u degx10'
     runTest()
     self.command = 'some other command'
     runTest() 

 def runTest(self):

     self.dest.PanTilt._y=2

     try:
        result = self.client.service.AbsoluteMove(self.token, self.dest, self.speed)
     except suds.WebFault as detail:
         print detail

     # self.command = './ptzpanposition -c 0 -u degx10'
     AbsoluteMove.Ssh(self)

     # Position of the camera verified through Ssh (No decimal point added to the Ssh value)
     self.assertEqual(self.Value, '200')

是否可以向Absolute Move添加另一个参数?

看起来self.command只是一个字符串,而且由于AbsoluteMove.Ssh()不带参数,因此它必须以某种方式使用该字符串…,因此您可以只更改self.command的值。更好的设计应该有两个命令,以及一个参数AbsoluteMove.Ssh()来选择它们。

很抱歉浪费时间

我已经在Ssh()函数中声明了这个变量。我删除了这个,随后在代码中更改了变量。代码将以这种方式工作,谢谢。

请阅读本页上的“我如何在这里提问?”