473,387 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Attribute value of instance method non-modifiable?

Hi!

I just stumbled over this:
..>>> class test(object):
.... def t(): pass
.... t.testval = 1
....
..>>> test.t
<unbound method test.t>
..>>> test.t.testval
1
..>>> test.t.testval = 2
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'instancemethod' object has no attribute 'testval'
..>>> dir(test.t)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__get__',
'__getattribute__', '__hash__', '__init__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__str__', 'im_class', 'im_func',
'im_self', 'testval']
test.t.im_func.testval = 2
test.t.testval 2


While I understand that a function is different from an instance method, it is
rather far from intuitive that the instance method provides read access to the
attribute of the enclosed function but not write access.

Does anyone know if this is a deliberate implementation decision? Is there any
reasoning behind that?

Stefan
Oct 26 '05 #1
0 1389

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

Similar topics

6
by: Ruud de Jong | last post by:
I have the situation where I need to construct the name of a static method, and then retrieve the corresponding function from a class object. I thought I could just use __getattribute__ for this...
7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
4
by: Donnal Walter | last post by:
This is a question about Python patterns or idioms. Over a period of time, I have evolved a pattern of usage that seems to work better for me than other ways I tried previously, but in writing some...
1
by: John | last post by:
I have an input document that contains a large base64 encoded document. This document also declares a schema location in the root element. I want to write an XSL stylesheet that makes an exact...
7
by: Brian Genisio | last post by:
Hello all, I am developing a class where speed is important, and memory size is also important. I need to give the user of the class read-only access to one of the private members (size as an...
3
by: Allerdyce.John | last post by:
I have a design type of quesiton. What is the advantages of using accessor (a getter/setter method) instead of making the attribute 'public'? If a class has public accessor (a getter/setter...
21
by: James Black | last post by:
I am curious if there is a benefit to set attributes directly, in my javascript, or to use setAttribute. For example, I have this: var input = document.createElementNS(xhtmlNS, 'input');...
3
by: Andrew Robinson | last post by:
I have created some custom attributes to help me map container objects to my back end SQL server. These contain object are decorated with my attributes. I am using the following code to read the...
6
by: Adam Donahue | last post by:
As an exercise I'm attempting to write a metaclass that causes an exception to be thrown whenever a user tries to access 'attributes' (in the traditional sense) via a direct reference. Consider:...
2
by: =?Utf-8?B?dXJrZWM=?= | last post by:
I am trying to create an in-process WMI provider using System.Management.Instrumentation namespace. For testing I use a simple class as a wrapper for FileInfo class. I have been able to use all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...

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.