Python meta object question

Gang Li gang.li at compuware.com
Wed Dec 1 16:26:15 EST 1999


You can try to change the base class for higher class. e.g.

localcompany.__base__ =  (Company2,)+localcompany.__base__[1:]
#assume the first base class is Company1, or you can find it by check all
base classes of it


"Mickael Remond" <mikl at linux-france.org> wrote in message
news:3842D025.3283C871 at linux-france.org...
> 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