Limits on number of classes?

J

John Hunter

Kamilche> My design reqires hundreds of classes, maybe over a
Kamilche> thousand. Can Python handle that? Will there be a speed
Kamilche> hit? Just wondering if anyone had hit the limits of

Never heard of such a problem. Here's a little script that creates
10000 classes; doesn't seem to strain python


for i in range(10000):
exec('class C%d: pass'%i)

c = C1234()
c.x = 1
print c.x
 
K

Kamilche

My design reqires hundreds of classes, maybe over a thousand. Can
Python handle that? Will there be a speed hit? Just wondering if
anyone had hit the limits of Python.
 
J

John Roth

Kamilche said:
My design reqires hundreds of classes, maybe over a thousand. Can
Python handle that? Will there be a speed hit? Just wondering if
anyone had hit the limits of Python.

Classes are first class objects like everything else. The only
limit on number of classes is the amount of memory - just
like everything else. That said, class objects are quite large
as such things go.

As far as performance goes, very deep inheritance structures
might take a bit of a performance hit since it has to check the
MRO on accesses.

John Roth
 

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

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top