469,936 Members | 2,422 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,936 developers. It's quick & easy.

getting the class name of a subclass

I have the following test code setup, trying to get the class name of a
subclass in the super class. (Reason why i want this is described below)

file class_name_start.py
========================
import class_name as cn

obj = cn.B()
obj.printclass()
========================
file class_name.py
========================
class A(object):
def __init__(self):
print "I'm A"

def printclass(self):
print "Name ",__name__
print "Class ",A.__name__

class B(A):
def __init__(self):
super(B,self).__init__()
print "I'm B"
========================

Output:
I'm A
I'm B
Name class_name
Class A

I would want the last line to be Class B
The reason i want this is since i have a number of dialogs all deriving
from the same super class. In the superclass i have a save function and
i thought it would be easy to get the classname and write the properties
in a filename with the classes name as the filename.
However it turns out i get the class name of the superclass for all.
All the different dialogs are in seperate files.

Is there a way to get the name of the subclass. If not i could always
pass a param to the init function but in my real life code i already
have several params shipped to the init so i wanted to solve it slightly
more elegant.

Regards,
Benedict
Jul 21 '05 #1
0 1223

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by bruno modulix | last post: by
3 posts views Thread by Mahesh Devjibhai Dhola | last post: by
25 posts views Thread by David Sanders | last post: by
9 posts views Thread by nik | last post: by
12 posts views Thread by Gordon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.