在继承的类中更改函数

时间:2019-03-01 18:20:04

标签: python

我有一个看起来像这样的课。

<?php
function liveExecuteCommand($cmd)
{

    while (@ ob_end_flush()); // end all output buffers if any

    $proc = popen("$cmd 2>&1 ; echo Exit status : $?", 'r');

    $live_output     = "";
    $complete_output = "";

    while (!feof($proc))
    {
        $live_output     = fread($proc, 4096);
        $complete_output = $complete_output . $live_output;
        echo "$live_output";
        @ flush();
    }

    pclose($proc);

    // get exit status
    preg_match('/[0-9]+$/', $complete_output, $matches);

    // return exit status and intended output
    return array (
                    'exit_status'  => intval($matches[0]),
                    'output'       => str_replace("Exit status : " . $matches[0], '', $complete_output)
                 );
}
    //$output = shell_exec('python C:/uboost/uboost.py pignalice Cazzo1234');
    liveExecuteCommand("python C:/uboost/uboost.py pignalice Cazzo1234");
?>

class General(Big_class): define func(self) self.x(arg) some_other_stuff x中的函数。我想创建一个新类,使我可以代替Big_class调用类似的函数,例如xy。有没有一种方法不涉及重新定义整个z函数呢?我不想这样做,因为func很长,我将不得不重复几次。

some_other_stuff

我可以改为在class Specific(General, Big_class): def func(self) self.y(arg) some_other_stuff 内执行类似的操作,然后将General设置为我希望它在a内的任何值吗?还是有什么我可以做的?

Specific

1 个答案:

答案 0 :(得分:1)

我正在阅读您的问题。

是否有一种方法可以保留func的所有功能,但要执行与x提供的功能不同的操作。

您获得解决方案的最初路径是要在此处调用其他名称,但是为什么不在子类中重新定义x

class Specific(General, Big_class):
   def x(self)
     # some different implementation
相关问题