Generic proxy (that proxies methods like __iter__)
spam2008 at nney.com
Thu Jan 28 14:54:16 CET 2010
On Jan 28, 1:31 pm, D HANNEY <spam2... at nney.com> wrote:
> Your solution works if I change "type(obj)" to say "obj.__class__".
> If I don't make this change Python complains "TypeError: Error when
> calling the metaclass bases type 'instance' is not an acceptable base
> So, I've got something that works but I don't understand why it works.
> I've read your docs.python reference but that hasn't helped yet. It
> might come to me but in the meantime, can you (or anyone) offer an
> explanation for this?
> Thanks in advance,
Oh it looks like this is py3K thing.
Python 3.0.1+ (r301:69556, Apr 15 2009, 15:59:22)
>>> from io import StringIO
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
>>> from StringIO import StringIO
<class StringIO.StringIO at 0xb7ea15fc>
I was using 2.6.2. Your suggestion would have been fine in py3k.
Even if I stuck with 2.6.2 and StringIO was a "new style class" there
then it would have been fine ... but it isn't.
As it stands __class__ seems the only way that works on both 3k and
Bit weird, but I get it now.
More information about the Python-list