473,326 Members | 2,076 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.

could that be a mutable object issue ?

If I do this:

print 'LEN OF BOOK BEFORE APPEND: ', len(pickle.dumps(self.__m_rw))
self.__m_rw.books.append( [p_col1,p_col2,p_col3] )
print 'LEN OF BOOK AFTER APPEND: ', len(pickle.dumps(self.__m_rw))

I get the same length before and after append.

when I print self.__m_rw.books, I see my 'appends' in there, yet the
pickled object does not change.

Any clue ?

Thanks
Philippe

--
***************************
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
***************************

Jul 18 '05 #1
2 1168
Philippe C. Martin wrote:
If I do this:

print 'LEN OF BOOK BEFORE APPEND: ', len(pickle.dumps(self.__m_rw))
self.__m_rw.books.append( [p_col1,p_col2,p_col3] )
print 'LEN OF BOOK AFTER APPEND: ', len(pickle.dumps(self.__m_rw))

I get the same length before and after append.

when I print self.__m_rw.books, I see my 'appends' in there, yet the
pickled object does not change.
How is __m_rw.books defined? If it is a class attribute of the class of __m_rw you will see this
behavior. e.g.
class Mrw: ... books = []
... m=Mrw()
class Mrw: ... books = []
... __m_rw = Mrw()
__m_rw.books.append(1)
__m_rw.books

[1]

but __m_rw.books will not be pickled with __m_rw because it belongs to the class, not the instance.

The fix is to declare books as an instance attribute:

class Mrw:
def __init__(self):
self.books = []

Kent

Any clue ?

Thanks
Philippe

Jul 18 '05 #2
You are correct and I still don't know Python (sigh).

Thanks

Philippe
On Sat, 19 Feb 2005 15:51:18 -0500, Kent Johnson wrote:
Philippe C. Martin wrote:
If I do this:

print 'LEN OF BOOK BEFORE APPEND: ', len(pickle.dumps(self.__m_rw))
self.__m_rw.books.append( [p_col1,p_col2,p_col3] )
print 'LEN OF BOOK AFTER APPEND: ', len(pickle.dumps(self.__m_rw))

I get the same length before and after append.

when I print self.__m_rw.books, I see my 'appends' in there, yet the
pickled object does not change.


How is __m_rw.books defined? If it is a class attribute of the class of __m_rw you will see this
behavior. e.g.
>>> class Mrw: ... books = []
... >>> m=Mrw()
>>> class Mrw: ... books = []
... >>> __m_rw = Mrw()
>>> __m_rw.books.append(1)
>>> __m_rw.books

[1]

but __m_rw.books will not be pickled with __m_rw because it belongs to the class, not the instance.

The fix is to declare books as an instance attribute:

class Mrw:
def __init__(self):
self.books = []

Kent

Any clue ?

Thanks
Philippe


Jul 18 '05 #3

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

Similar topics

17
by: Gordon Airport | last post by:
Has anyone suggested introducing a mutable string type (yes, of course) and distinguishing them from standard strings by the quote type - single or double? As far as I know ' and " are currently...
50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
3
by: Ingo Nolden | last post by:
Hi, I try to use const where ever appropriate. In a collection class I am counting the iterators that are out. The counter decrements when an iterator leaves scope or is 'Dispose( )'d While...
6
by: christopher diggins | last post by:
I wrote a dynamic matrix class similar to the one described in TCPL 3rd Edition. Rather than define two separate iterators for const and non-const scenarios I decided to be a lazy bastard and only...
5
by: Pelle Beckman | last post by:
Hi, Honestly, what is this 'size_t'? And while I'm at it - what is a 'mutable' var.? I've understood it somehow makes a const a non-const, but what's the point of that? Short explanations?...
18
by: Markus.Elfring | last post by:
The C++ language specification provides the key word "mutable" that is not available in the C99 standard. Will it be imported to reduce any incompatibilities?...
12
by: Kjetil Kristoffer Solberg | last post by:
What is a mutable struct? regards Kjetil Kristoffer Solberg
12
by: Vincent RICHOMME | last post by:
Hi, I am currently implementing some basic classes from .NET into modern C++. And I would like to know if someone would know a non mutable string class.
1
by: Let_Me_Be | last post by:
Hi, I'm kinda worndering how the mutable keyword works. Because of speed, I added value caching into my base class, and the only posible way to implement this seemed to be adding the mutable...
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
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...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.