473,595 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

making objects unassignable "read-only" (especially when extending)

Hi,

can I make an object read-only, so that

x = new_value

fails (and x keeps it's orginal value)?

This would be especially of interest for me for an object created by
a c extension.

--
Johannes
Jan 18 '06 #1
3 3593
On 18 Jan 2006 11:59:23 GMT, Johannes Zellner <jo******@zelln er.org> wrote:
Hi,

can I make an object read-only, so that

x = new_value

fails (and x keeps it's orginal value)?


This works for me:

http://groups.google.com/group/comp....1785397358ff90

--
Cheers,
Simon B,
si***@brunningo nline.net,
http://www.brunningonline.net/simon/blog/
Jan 18 '06 #2
Johannes Zellner wrote:
Hi,

can I make an object read-only, so that

x = new_value

fails (and x keeps it's orginal value)?


Simon gave you a way of doing it when x is an attribute access (e.g.
p.x). I am unaware of a way of doing it when x is a straight global or
local. Unlike other languages like C, the object pointed to by a
variable is in no way involved in the assignment process. Variables are
just labels (sticky notes) attached to objects. Assignment is moving of
the label - this only involves the interpreter, and the object currently
labeled by the variable is not consulted. If you haven't seen it before,
http://starship.python.net/crew/mwh/...jectthink.html is a good read.

Note that Simon's trick works not because it changes the object pointed
to by the variable, but because it changes the properties of the
namespace where that variable lives (the p in the p.x). To do so for a
local or a global variable would require changing the local & global
namespaces - i.e. rewriting the interpreter.
Jan 18 '06 #3
Johannes Zellner wrote:
can I make an object read-only, so that

x = new_value

fails (and x keeps it's orginal value)?


the original x does contain the original value; assignment only changes
the binding in the target namespace. you cannot override this.

you can control attribute assignment, though:

x.y = new_value

(via __setattr__ methods/slots on the x object)

</F>

Jan 18 '06 #4

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

Similar topics

1
3329
by: ParkPD | last post by:
Hi, I have been made a signed-applet that handling xml data from web-server. When I execute this applet with appletviewer, it works well. And it is OK with Internet Explorer. But when I opened this page with Netscape 7.0(OS is Windows XP sp1), this applet throw exception when reading xml data from web server. the error message is like this, "Exception : java.security.AccessControlException: access
4
3408
by: Askari | last post by:
Yesterday, ALL code in python work and nothing when I close(finish) a code. Today, when I close, some raise this windows error : Instruction at "0x00FC3D70" use memory address "0x00000000". Can't be "read". Click on "OK" to exit program. Why this error, today and not before today?
10
2272
by: ZafT | last post by:
Thanks in advance for any tips that might get me going in the right direction. I am working on a simple exercise for school that is supposed to use read to read a file (about 10 MB). I am supposed to change the buffer size and see how this affects the read time. In other words, the buffer is supposed to limit how much of the file gets read per call, and cause some change in speed. I am supposed to do the same with fread as well, but...
0
2126
by: antsays | last post by:
I am trying to serialize a collection to disk using the code provided. This works just fine but when I try do copy and past the xml file to another location or sometimes even just click on the file it gives me the error: The instruction at "0x635e0719" referenced memory at "0x00000000". The momory could not be "read. Could anyone please help out with this
2
5184
by: Ryan Linneman via .NET 247 | last post by:
Any help appreciated... I am using a third party DLL file to access an HMI using ethernet. The function is declared in a VB module as: 'Read internal word address Public Declare Function HKEtn_ReadInternalMemory Lib "HKEserv.dll" _ (ByRef dp As Int16, _ ByVal Wordcnt As Int16, _ ByVal DeviceType As Int32, _ ByVal addr As Int32, _
4
3467
by: MarkusR | last post by:
If I run the stored proc in the Query Analyzer this works and I get the expected result set back. However when I run it in my application I get a results set of one row but when I try to access the values I get "Invalid attempt to read when no data is present". private void GetLotIDPriorityFromLot(string aLotDesc, out int aLotID, out DateTime aPriorityDate) { SqlConnection Conn; SqlDataReader reader = null;
3
6517
by: divsTiw | last post by:
I want to populate combo box with data from OracleDataReader , but "Invalid attempt to read when no data is present." is thrown. there are two rows returned , then too why such error. plzzz share ur knowledge to help me out with this probs. my code is as below,
6
2894
by: Lighter | last post by:
How to read "The lvalue-to-rvalue, array-to-pointer, and function-to- pointer standard conversionsare not applied to the left expressions"? In 5.18 Comma operator of the C++ standard, there is a rule: "The lvalue-to-rvalue, array-to-pointer, and function-to-pointer standard conversionsare not applied to the left expressions" I could not understand what the rule means. I also searched the web and the groups and got nothing.
3
12550
by: mohammadazim | last post by:
Hi guys I wrote a socket program in c++ and used blocking system call read () for receiving data on socket. But it gives following error while compilation g++ -Wall -g -I`pwd`/../include -lpthread -c SocketDescriptor.cc -o `pwd`/../lib/SocketDescriptor.o SocketDescriptor.cc: In member function ‘Status SocketDescriptor::Recv(int&, unsigned char*, int&)’: SocketDescriptor.cc:79: error: ‘read’ was not declared in this scope make: *** Error...
1
3742
by: kamcap | last post by:
I have referenced a COM dll (unmanagged code) in a C# console application and this DLL is referenced in C# program using Interop facility in .NET. This dll actually a dataset/table which is written in Borland Delphi. static int Main(string args) { ClientVarDataSet vds = new ClientVarDataSet(); vds.XML = ""; vds.AddField("x", 3); //"x" field name and 3 field type
0
7883
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
8261
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
8379
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
8019
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
8251
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...
1
5839
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3873
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
2391
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
0
1223
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.