문제

I have a class holding a table (list of lists). This class should return a rowpointer similar to sql. For this row pointer I would like to week ref the table row (a list) with a weakref.proxy. However, I would like to add additional capabilities to a row pointer, e.g. overwrite the __getitem__ method to allow access via, say the column names.

Is there an easy way to get the same behaviour (translating access to my object to the object beeing referenced), or do I have to reimplement all the special methods?

As an easy way I could think of inheritance (but since I found no doc on weakref.ProxyType I wont even try to inherit from that, (how to init?). The other option could be to define some special method even to always redirect "special" (__xxx__) function calls to the referred object, even though this makes that seem impossible.

도움이 되었습니까?

해결책

Iresearched some more and found out this:

http://code.activestate.com/recipes/496741-object-proxying/ http://pypi.python.org/pypi/ProxyTypes

So in short, one can forward all calls (I think the recipi on active state is better), but I have not found a way to implement:

$a = proxy([1,2,3])
$b = a
$print type(b)   
>>list

I will settle for just working with an object wich pretty much behaves like the list.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top