Inheritance in nested classes

M

Martin Skou

I'm experimenting with using Python for a small web interface, using
Mark Hammond's nice win32 extensions.

I use a small class hierarchy which uses inheritance and nested classes.

Here are a small extract of the code:

class page:

def __init__(self):
self.head=[]

def __str__(self):
...

class simple_tag:
...

class p(simple_tag):
...

class table:
...

class row:
...

class data:
...
...


Will this type of code perform noticable slower than unnested classes?

I'm using the Active Server Pages integration in the win32 extensions,
does anyone have good/bad experiences using this interface?

Thanks.

/Martin
 
D

Diez B. Roggisch

Martin said:
I'm experimenting with using Python for a small web interface, using
Mark Hammond's nice win32 extensions.

I use a small class hierarchy which uses inheritance and nested classes.

Here are a small extract of the code:

class page:

def __init__(self):
self.head=[]

def __str__(self):
...

class simple_tag:
...

class p(simple_tag):
...

class table:
...

class row:
...

class data:
...
...


Will this type of code perform noticable slower than unnested classes?

I'm not aware that there is much runtime penalty here - a quick test
reveals that:

import time

class Foo:
def __init__(self, baz):
self.baz = baz

def unnested():
o = Foo(10)

def nested():
class Foo:
def __init__(self, baz):
self.baz = baz



then = time.time()
for i in xrange(100000):
unnested()
print time.time() - then

then = time.time()
for i in xrange(100000):
nested()
print time.time() - then


Yields

0.839588165283
0.817638158798

for me.

But I hope you are aware that nested classes aren't quite the same as
they are in java, are you?

Regards,

Diez
 
G

gmilas

"I'm using the Active Server Pages integration in the win32 extensions,

does anyone have good/bad experiences using this interface?"

What is it you are trying to do?
I'm using python2.4 with win32 and IIS/python ASP and find it ok. There
were at some point some session overlappings but I'm not sure if it was
the asp interface or my ajax code?

Anyway I have someting you may find usefull in doing asp with python at
http://www.emilas.com/pwh/
and this has an ORM that has an html form generator if I guess your
intention of generating html using python. The generator there is not
general but rather oriented towords databases tables and views.
 

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
473,781
Messages
2,569,619
Members
45,316
Latest member
naturesElixirCBDGummies

Latest Threads

Top