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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/155.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:向类添加默认函数??或者类运算符不确定_Python - Fatal编程技术网

Python:向类添加默认函数??或者类运算符不确定

Python:向类添加默认函数??或者类运算符不确定,python,Python,我仍在学习很多东西。所以请放松点。:) 我有两个班,每个人和那里的兄弟在工作中使用。我想添加一些功能 第1类: foo_the_unchange(具有python包装器的c代码,是我们产品的接口库) 第2类: 所有人使用的食物 m=foo_the_unchangeable() 所以,当我为我们的产品编写测试脚本时,我确实会这样想 MyObj = foo_used_by_all() x = MyObj.m.Item("some text showing product options").Va

我仍在学习很多东西。所以请放松点。:)

我有两个班,每个人和那里的兄弟在工作中使用。我想添加一些功能

第1类: foo_the_unchange(具有python包装器的c代码,是我们产品的接口库)

第2类: 所有人使用的食物

m=foo_the_unchangeable()
所以,当我为我们的产品编写测试脚本时,我确实会这样想

MyObj = foo_used_by_all()

x = MyObj.m.Item("some text showing product options").Value
z = MyObj.m.Item("some text showing product options").DisplayValue

我不知道怎么做的类foo_使用了_所有这样我就可以写脚本的方式,我想。 我能够创建一个返回类的成员函数。很接近;但这不是我想要的

foo_used_by_all
  def Item(self, text_str)
    return self.m.Item(text_str)

如果有人能给我指出正确的方向,那会很有帮助。

看起来你想实现
\uuuu call\uuuu()
方法:

class UsedByAll:

    def __init__(self):
        self.api = TheUnchangeable()

    def __call__(self, text):
        return self.api.Item(text)
给出了显示的名称,请查看。

如何

MyObj = foo_used_by_all()
MyItem = MyObj.m.Item    # or MyObj = MyObj.m.Item
然后


MyObj=()
没有任何意义,也许你应该用文字解释一下那是怎么回事。这是我的打字错误。它应该是MyObj=foo被所有人使用的()
foo_used_by_all
  def Item(self, text_str)
    return self.m.Item(text_str)
class UsedByAll:

    def __init__(self):
        self.api = TheUnchangeable()

    def __call__(self, text):
        return self.api.Item(text)
MyObj = foo_used_by_all()
MyItem = MyObj.m.Item    # or MyObj = MyObj.m.Item
x = MyItem("some text showing product options").Value
Y = MyItem("some text showing product options").DisplayValue
MyItem("some text showing product options").Value = 9
MyItem("some text showing product options").DisplayValue = "Mark"