Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Outdated statement in docs comparing pickle with marshal #143928

Closed
Labels
docsDocumentation in the Doc dir
@aescarias

Description

@aescarias

I found this statement in thepickle docs comparing the pickle module with the marshal module:

The pickle module differs from marshal in several significant ways:

  • The pickle module keeps track of the objects it has already serialized, so that later references to the same object won’t be serialized again. marshal doesn’t do this.

    This has implications both for recursive objects and object sharing. Recursive objects are objects that contain references to themselves. These are not handled by marshal, and in fact, attempting to marshal recursive objects will crash your Python interpreter. Object sharing happens when there are multiple references to the same object in different places in the object hierarchy being serialized. pickle stores such objects only once, and ensures that all other references point to the master copy. Shared objects remain shared, which can be very important for mutable objects.

However, this appears to no longer be the case asmarshal version 3 (added in Python 3.4) supports keeping track of objects via references and as such is capable of serializing recursive objects.

>>>import marshal>>> xs= [1,2,3]>>> xs.append(xs)>>> marshal.dumps(xs)b'\xdb\x04\x00\x00\x00\xe9\x01\x00\x00\x00\xe9\x02\x00\x00\x00\xe9\x03\x00\x00\x00r\x00\x00\x00\x00'

(in Python 3.3,marshal.dumps(xs) fails withValueError: object too deeply nested to marshal)

So I don't see any reason for this statement to be in the docs in its current state.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp