[Tutor] how-to do black magic

Gonçalo Rodrigues op73418@mail.telepac.pt
Fri May 16 06:57:02 2003


----- Original Message -----
From: "Adam Groszer" <adamg@mailbox.hu>
To: "Tutor@Python. Org" <tutor@python.org>
Sent: Friday, May 16, 2003 9:13 AM
Subject: [Tutor] how-to do black magic


> Dear All,
>
> How-to do the following.
> I have a list of properties let's say in a text file.
> From this list I'd like to create a class's properties and getter/setter
> methods with a metaclass.
> Is this possible? How?
>
> example:
>
> text file:
> Name
> Value
>
> class:
> class sample(base):
> def setName(self, val):
> self.__Name=val
> def getName(self):
> return self.__Name
> Name = property(getName, setName, None, 'this is my Name')
> def setValue(self, val):
> self.__Value=val
> def getValue(self):
> return self.__Value
> Value = property(getValue, setValue, None, 'this is my Value')
>
> something like this, or likely behavior
>
> Adam
>

The recipe

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/157768

and its (long) discussion should give you a head start.

But from what I gather from your specs, you need only a name to specfiy a
property, that consists simply in a setting/getting from a "private"
attribute. Are you sure you need black magic for just this? Isn't there a
simpler way to accomplish whatever you are trying to do, ditching properties
altogether? Tell us a little more about your problem.

Also, you may have more luck in the python list for this more advanced
stuff, you have a wider audience.

All the best,
G. Rodrigues