473,326 Members | 2,655 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,326 software developers and data experts.

Don't want to serialize a variable of object


Hi,
I got a class which I need to serialize, except for couple of variable.
i.e.

import cPickle as p
class Color:
def __init__(self):
print "hello world"
self.x=10
self.somechar="this are the characters"
color=Color()
f=file('poem.txt', 'w')
p.dump(color, f)
f.close()

How do I serialize the object color without serializing the x and
somechar variables?
Is there any modifier which prevents the variable from being serialized.


Another question:
Is there a concept of private variables?

regards
prasad chandrasekaran










--- Cancer cures smoking
#-----Original Message-----
#From: py*********************************************@py thon.org
#[mailto:py***************************************** ****@python.org] On
#Behalf Of py*****************@python.org
#Sent: Tuesday, October 18, 2005 11:00 AM
#To: py*********@python.org
#Subject: Python-list Digest, Vol 25, Issue 322
#
#Send Python-list mailing list submissions to
# py*********@python.org
#
#To subscribe or unsubscribe via the World Wide Web, visit
# http://mail.python.org/mailman/listinfo/python-list
#or, via email, send a message with subject or body 'help' to
# py*****************@python.org
#
#You can reach the person managing the list at
# py***************@python.org
#
#When replying, please edit your Subject line so it is more specific
#than "Re: Contents of Python-list digest..."

This message contains information that may be privileged or confidentialand is the property of the Capgemini Group. It is intended only for theperson to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive thismessage in error, please notify the sender immediately and delete all copies of this message.

Oct 18 '05 #1
1 2025
Iyer, Prasad C wrote:
How do I serialize the object color without serializing the x and
somechar variables?
Is there any modifier which prevents the variable from being serialized.
See the pickle documentation. The example given in the documentation
pickles a class while excluding one of its attributes.

http://www.python.org/doc/2.4.2/lib/pickle-example.html
Another question:
Is there a concept of private variables?


'private variables' can mean either of two things: hiding the variables to
prevent accidental naming conflicts in subclasses, or security to prevent
malicious manipulation of a class's internal state.

Python provides the former (to a certain extent) when you give an attribute
a name prefixed with a double underscore, but makes no attempt to provide
the latter. Some other languages (such as C++) make no attempt to provide
the former and a completely inadequate attempt at the latter.

In other words: Python has a concept of private variables, but it is
different than in some other languages, and if you google past threads you
can find endless discussions on the pro's and con's of the Python approach.
Oct 18 '05 #2

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

Similar topics

7
by: Ian Tompsett | last post by:
H I was wondering if it possible for an object to serialize/deserialize itself from XML. I'd be guessing that it would need to use the XmlSerializer class, but that seems to want to create a...
4
by: _BNC | last post by:
I've got an ArrayList of objects that I'd like to save/retrieve as quickly as possible. Each item in the arraylist is an object with about 50 variable-length strings; many zero-length, some about...
1
by: Tim Faircloth | last post by:
When you serialize an object into xml is there a way to write this information into a string variable instead of a file.
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
1
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
10
by: Dan | last post by:
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That public string SaveNewSurvey( MutualSurveyObject mso_TempObject, int i_JobID ) { string s_RootFileName;...
3
by: MAY | last post by:
Hi, I have a problem about serialize the form controls. I wrote a test program to test serialize a from but fail (->An unhandled exception of type...
3
by: Gordz | last post by:
I've been experiencing problems on some computers with XML Serialization. On some computers the files do not get created on the web server's hard drive and it's been driving me nuts trying to...
2
by: alexandre martins | last post by:
Every time i try to make Deserialize the computer gives me the folowing error: "End of Stream encountered before parsing was complete" the code that i'm running is simple and is based on an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.