我想在PIL中扩展“Image”类。在
#module Image
def open(file): ...
class Image:
def method1:...
def method2:...
#module myOriginal
from Image import Image
class ExtendedImage(Image):
def method3:...
#module test
import myOriginal
im = myOriginal.open("picture.jpg")
结果:错误.myOriginal没有“打开”属性。在
如何在不重写open()方法的情况下扩展Image类?在
According to Fredrik Lundh,PIL的作者:
肌原创性.py:
委派个别方法:
或者要(几乎)将所有内容委托给
^{pr2}$self._img
,可以使用__getattr__
:测试.py:
相关问题 更多 >
编程相关推荐