Is their an expression to create a class?

P

Paddy

We the def statement and the lambda expression. We have the class
statement, but is their an expression to create a class?

Or:

Thanks.

- Paddy.
 
R

Robert Kern

We the def statement and the lambda expression. We have the class
statement, but is their an expression to create a class?

Or:

type('O', (object,), {})

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
C

Chris Rebert

type('O', (object,), {})

Further detail from the docs (http://docs.python.org/library/functions.html):

type(name, bases, dict)

Return a new type object. This is essentially a dynamic form of
the class statement. The name string is the class name and becomes the
__name__ attribute; the bases tuple itemizes the base classes and
becomes the __bases__ attribute; and the dict dictionary is the
namespace containing definitions for class body and becomes the
__dict__ attribute. For example, the following two statements create
identical type objects:
... a = 1
...
New in version 2.2.

Cheers,
Chris
 
D

Donald 'Paddy' McCarthy

Chris said:
Further detail from the docs (http://docs.python.org/library/functions.html):

type(name, bases, dict)

Return a new type object. This is essentially a dynamic form of
the class statement. The name string is the class name and becomes the
__name__ attribute; the bases tuple itemizes the base classes and
becomes the __bases__ attribute; and the dict dictionary is the
namespace containing definitions for class body and becomes the
__dict__ attribute. For example, the following two statements create
identical type objects:

... a = 1
...

New in version 2.2.

Cheers,
Chris


Thanks guys. Youve put my mind at rest!

- Paddy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,206
Latest member
EpifaniaMc

Latest Threads

Top