Python meta object question

Mickael Remond mikl at linux-france.org
Mon Nov 29 14:12:37 EST 1999


Hello,

Is there a way to automatically update the class tree to show the change
in inherited class attributes after a class redefinition ?


Look at this example:

----------------------------------------
# Step one
# First description
class company1:
    company = "Company1"

class company2:
    company = "Company2"

class localcompany(company1):
    localcompany = "STE France"

class employee(localcompany):
    employee = "Me"

print
print "Step 1:"
print localcompany.company         # => Company1
print employee.company             # => Company1

# Step two
# localcompany is sold to company2
class localcompany(company2):
    localcompany="New STE France"

print
print "Step 2:"
print localcompany.company         # => Company2
print employee.company             # => Company1 (outdated!)

# Step three
# Force employee class update (same class definition)
class employee(localcompany):
    employee = "Me"

print
print "Step 3:"
print localcompany.company         # => Company2
print employee.company             # => Company2
-------------------------------------------------------------

This case is very simple but when the class tree becomes complicated it
is difficult to keep all class up to date.

Is there a way to redefined only one class, as in step 2 and have all
the other class automatically take this change into account ?

Thank you in advance for your help.

Mickael Remond




More information about the Python-list mailing list