473,511 Members | 15,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

properties access by name

I use rwproperty (http://pypi.python.org/pypi/rwproperty/1.0) and so I
have properties in my class. Also I have a list of names of properties
wich I am to set. How can I access my properties by name in such way
that when I want to set a property, setter will be called, and and
when I want to read it - getter?

I have something like this:

class Film(object):
def __init__(self, title):
self.__title = title

@getproperty
def title(self):
return self.__title
@setproperty
def title(self, value):
self.__title = value

properties_to_set = ['title']
f = Film('aaa')

I d want to have sth like:
f(properties_to_set[0]) = 'bbb'

If title was a simple variable I could write:
f.__dict__[properties_to_set[0]] = 'bbb'

now I can write:
f.__dict__['_Film__' + properties_to_set[0]] = 'bbb'

but I want to set my property through the provided setter. How can I
do this?

P.S. Sorry for my english
Oct 17 '08 #1
1 1257
=?KOI8-R?B?7cnU0Q==?= wrote in news:f1a77a69-2997-4f53-9a46-
f8**********@m3g2000hsc.googlegroups.com in comp.lang.python:
>
class Film(object):
def __init__(self, title):
self.__title = title

@getproperty
def title(self):
return self.__title
@setproperty
def title(self, value):
self.__title = value

properties_to_set = ['title']
f = Film('aaa')
Ther is a builtin `setattr` to do this:

#http://www.python.org/doc/2.5.2/lib/built-in-funcs.html

setattr( f, "title", "bbb" )

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Oct 17 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2932
by: Pato Secruza | last post by:
Hi everyone! I have a really frustrating error and need help. I’m trying to do a function that gets the properties and names of the fields in a MS Access database using ASP. I haven’t...
8
16627
by: deko | last post by:
I'm trying to find a way to set form/control properties programmatically. In a nut shell: 1. Open a database 2. Open a form in design view 3. Do something like this: For Each prp In...
8
3331
by: deko | last post by:
I'm hoping someone can sanity check my understanding of the Object Model for Forms/Controls. I'm having trouble drilling down into Control properties. First, I have a record set with the...
2
7738
by: Dennis Ruppert | last post by:
I created a routine to read and edit the description properties of tables, (the one you see in the database window). It works just fine. This is the basic code behind it, I substituted all my...
4
7488
by: Lyn | last post by:
Hi, This question may seem a bit academic... To learn more about Access VBA, I have been enumerating the properties of various form controls. This was mostly successful and I have learned a lot...
18
18309
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
10
7341
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
11
1776
by: john andrew | last post by:
-- hello When using properties with OOP, VB6 had Get/Let and VB.net has Readonly/and .... Are theses OOP concepts with Property use or only specific to Visual Basic properties, With this...
2
7962
by: Greg Strong | last post by:
Hello All, Is it possible to change table field lookup properties in code? I've been able to change other field properties in code, however so far no luck with field lookup properties. What...
17
4003
by: The Frog | last post by:
Hello everyone, I am working on an application that can build database objects in MS Access from text files. I suppose you could call it a backup and restore type routine. Accessing the...
0
7430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.