Python meta object question
Arpad Kiss
sekter at mail.matav.hu
Wed Dec 1 05:44:15 EST 1999
----- Original Message -----
From: Mickael Remond <mikl at linux-france.org>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Wednesday, December 01, 1999 7:29 AM
Subject: Re: Python meta object question
> Mickael Remond wrote:
> >
> > Hello,
> >
> > Is there a way to automatically update the class tree to show the change
> > in inherited class attributes after a class redefinition ?
> >
>
> [...]
>
> In fact, this example was an attempt at using meta programming features
> of python.
>
> In a Bytes Magazine article (1997) I read that :
>
> For a programming language, Python is flexible. Classes and method
> refer ences in Python are treated as first-class objects. That is,
> new methods and member variables can be added to a class at any
> time, and all existing and future instances of classes are affected
> by these changes. This way, a scheduled event on a server program
> can change a variable in the class definition that defines each
> user's privileges. Thus, when standard office hours end, access
> could be broadened automatically to certain users with a single
> line of code such as userClass.restrictions=3 . All existing and
> future instances of userClass are updated and use this new value
> until the class variable is changed again. A programmer maintaining
> the code for the server could log in and be allowed to add or
> update classes and methods without having to take the server down.
>
> I did not find any clue on how to leverage these features. Are they out
> of date ?
Well, I use member variables this way:
>>> class a:
... ca="dog"
... def __init__(self,name):
... self.name=name
...
>>> mydog=a("tibi")
>>> mydog.ca, mydog.name
('dog', 'tibi')
>>> a.ca="cat"
>>> mydog.ca, mydog.name
('cat', 'tibi')
Arpad
>
> Mickael Remond
>
More information about the Python-list
mailing list