type() takes one or *three* arguments!?

jamesthiele.usenet at gmail.com jamesthiele.usenet at gmail.com
Sun Jan 30 20:57:23 CET 2005


I was looking at Simon Burton's Povray.py code (part of pypov) and saw
this line:
globals()[name] = type( name, (KWItem,), {} ) # nifty :)

where 'KWItem' was a class. It did seem nifty, but it was unclear to me
what was happening.

I went to python.org's online documentation which said that type()
takes one argument. So I fired up python:
>>> type(42)
<type 'int'>
>>> type("x", (type(42),), {})
<class '__main__.x'>

OK, It appears that type() with 3 arguments constructs a class. Is this
documented somewhere? If not can someone explain what is going on?
james




More information about the Python-list mailing list