meteclasses 2.x/3.x compatibility

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Apr 20 05:56:58 EDT 2011


On 2011年4月20日 11:56:35 +1000, James Mills wrote:
> Hi all,
>> Is there a compatible way to use meteclasses in both Python 2.x (2.6 to
> 2.7) and Python 3.x (3.0 to 3.2).

Untested:
if sys.version >= "3":
 kw = {'metaclass': MyMetaClass}
else:
 kw = {}
class Foo(object, **kw):
 if sys.version < "3":
 __metaclass__ = MyMetaClass
Inelegant as it gets, but it should work.
-- 
Steven


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /