473,670 Members | 2,724 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_s et = ['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_s et[0]] = 'bbb'

now I can write:
f.__dict__['_Film__' + properties_to_s et[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 1262
=?KOI8-R?B?7cnU0Q==?= wrote in news:f1a77a69-2997-4f53-9a46-
f8**********@m3 g2000hsc.google groups.com in comp.lang.pytho n:
>
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_s et = ['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
2944
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 programmed in a while so I’m quite lost. Once I have the my database structure I will insert the corresponding fields from a web form but the database is huge and I want to be able to change the database and form without changing the ASP code all the
8
16660
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 frm.Properties If prp.Name = rst!PropName Then prp = rst!ChangeTo
8
3353
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 following for a given Form: 1)Container
2
7744
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 editing/updating code with the debug.print to keep it simple. Function EditTableDescriptions() On Error GoTo Err_EditTableDescriptions Dim db As DAO.Database Dim tbl As DAO.TableDef
4
7512
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 from the process. It occurred to me that I could also enumerate the properties of the ADO Recordset in similar fashion, expecting to get back known properties such as AbsolutePosition, BOF, EOF, Filter, Sort, etc. I inserted the following
18
18362
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 a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
10
7360
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 Windows.Forms.UserControl in a COM environment, i.e. I want to host that control in a COM host. So far, so good, I can host it, but I can not reach the parent COM object from the control (Parent property is null :( ). I have stopped the control in the...
11
1787
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 property use does C++ have this as well or just Visual C++.?
2
7979
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 I've done for test purposes is use a text input file for the table field lookup properties. I thought that I'd start first by just changing the 'Display Control' property. Thanks to Allen Browne for some ideals per...
17
4019
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 fields, tables, relationships, and indexes is no issue for me via DAO code. The issue I have is that I am not sure which properties are actually necessary / available to set from code for each possible type of field. I have looked fo´r a reference on...
0
8471
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8815
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8592
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8661
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7421
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4213
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2802
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 we have to send another system

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.