type() takes one or *three* arguments!?
jamesthiele.usenet_at_gmail.com
Date: 01/30/05
- Next message: ssaeed1973_at_yahoo.com: "Re: Need programming tip"
- Previous message: Bryan: "Re: The next Xah-lee post contest"
- Next in thread: Pedro Werneck: "Re: type() takes one or *three* arguments!?"
- Reply: Pedro Werneck: "Re: type() takes one or *three* arguments!?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Jan 2005 11:57:23 -0800
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
- Next message: ssaeed1973_at_yahoo.com: "Re: Need programming tip"
- Previous message: Bryan: "Re: The next Xah-lee post contest"
- Next in thread: Pedro Werneck: "Re: type() takes one or *three* arguments!?"
- Reply: Pedro Werneck: "Re: type() takes one or *three* arguments!?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]