473,396 Members | 1,724 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,396 software developers and data experts.

Mark attribute as read-only

Hello,
how can I mark a attribute of a class as read-only (for non classmembers)?
Yes, stupid question, but the docu gave me no help.

Thanks,

Florian
Jul 18 '05 #1
1 1261
Florian Lindner wrote:
how can I mark a attribute of a class as read-only (for non classmembers)?
Yes, stupid question, but the docu gave me no help.


Declare it as such in the documentation. ;)

If you want to provide error messages, you could alternatively define a
property:

py> class C(object):
.... def _getx(self):
.... return self._x
.... x = property(fget=_getx)
.... def __init__(self, x):
.... self._x = x
....
py> c = C(4)
py> c.x
4
py> c.x = 6
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
AttributeError: can't set attribute

STeVe
Jul 18 '05 #2

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

Similar topics

4
by: Guy | last post by:
I'd like so that when a user moves there mouse over an image (or clicks the image, either way it doesn't matter), I'd like some text to appear. I was going to use the img tag with the alt...
5
by: Gregg | last post by:
Hello all, I have been banging my head over a problem that I am having reading a comma seperated file (CSV) that can contain from 1 to 10,000 records. My code snipit is as follows: **Start...
6
by: Richard | last post by:
<a href="#" name="sample">link 1</a> <a href="#" name="sample">link 2</a> Would this be invalid use of the name? If I wanted to have a function that would be acted upon by detection of the...
2
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this...
2
by: JMonnin | last post by:
I'm using an XmlValidatingReader to read an XML document and parse it against my schema. While I'm reading each node, I need to determine if the schema allows an ID attribute for the node. The ID...
3
by: Carl Lindmark | last post by:
*Cross-posting from microsoft.public.dotnet.languages.csharp, since I believe the question is better suited in this XML group* Hello all, I'm having some problems understanding all the ins and...
11
by: Mark A | last post by:
Here is Mark Townsend's (Oracle Product Manager) explanation and justification for posting in the DB2 newsgroup, as posted on the Oracle newsgroup, and my response: "Mark Townsend"...
3
by: Patrick Blackman | last post by:
Need example of how to use the flags attribute and to determine which flags were set.
18
by: Gabriel Rossetti | last post by:
Hello everyone, I had read somewhere that it is preferred to use self.__class__.attribute over ClassName.attribute to access class (aka static) attributes. I had done this and it seamed to work,...
0
by: Terry Reedy | last post by:
"Casey McGinty" <casey.mcginty@gmail.comwrote in message news:ae3f58470806051341s75052c29s7adcc4c994462618@mail.gmail.com... | On Thu, Jun 5, 2008 at 5:40 AM, Gabriel Rossetti < |...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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...
0
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
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,...

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.