marshal bug?
Gary Herron
gherron at islandtraining.com
Fri Sep 28 03:06:55 EDT 2007
Anurag wrote:
> I have been chasing a problem in my code since hours and it bolis down
> to this
> import marshal
> marshal.dumps(str(123)) != marshal.dumps(str("123"))
>
> Can someone please tell me why?
> when
> str(123) == str("123")
>
> or are they different?
>
> it also means that
> if s = str(123)
> marshal.dumps(s) != marshal.dumps(marshal.loads(marshal.dumps(s)))
>
> rgds
> Anurag
>
>
Any string in Python can be "interned" or not, the difference being
how/where the value is stored internally. The marshal module includes
such information in its output. What you are doing is probably
considered a misuse of the marshal module. I'd suggest using the pickle
(or cPickle) modules instead.
Here's the relevant part of the manual for marshal:
version:
Indicates the format that the module uses. Version 0 is the
historical format, version 1 (added in Python 2.4) shares interned
strings and version 2 (added in Python 2.5) uses a binary format for
floating point numbers. The current version is 2
Gary Herron.
More information about the Python-list
mailing list