Pelokalan
Python ID
id en
Masuk
Proyek
library__marshal.po Berkas proyek · python-docs-id-3.14 · Bahasa Indonesia
Modul PO Hanya lihat
Teks sumber — English
Terjemahan — Bahasa Indonesia
:mod:`!marshal` --- Internal Python object serialization
This is not a general "persistence" module. For general persistence and transfer of Python objects through RPC calls, see the modules :mod:`pickle` and :mod:`shelve`. The :mod:`!marshal` module exists mainly to support reading and writing the "pseudo-compiled" code for Python modules of :file:`.pyc` files. Therefore, the Python maintainers reserve the right to modify the marshal format in backward incompatible ways should the need arise. The format of code objects is not compatible between Python versions, even if the version of the format is the same. De-serializing a code object in the incorrect Python version has undefined behavior. If you're serializing and de-serializing Python objects, use the :mod:`pickle` module instead -- the performance is comparable, version independence is guaranteed, and pickle supports a substantially wider range of objects than marshal.
There are functions that read/write files as well as functions operating on bytes-like objects.
Not all Python object types are supported; in general, only objects whose value is independent from a particular invocation of Python can be written and read by this module. The following types are supported:
Strings (:class:`str`) and :class:`bytes`. :term:`Bytes-like objects <bytes-like object>` like :class:`bytearray` are marshalled as :class:`!bytes`.
:class:`code <types.CodeType>` objects, if *allow_code* is true. See note above about version dependence.
If the value has (or contains an object that has) an unsupported type, a :exc:`ValueError` exception is raised --- but garbage data will also be written to the file. The object will not be properly read back by :func:`load`. :ref:`Code objects <code-objects>` are only supported if *allow_code* is true.
Read one value from the open file and return it. If no valid value is read (e.g. because the data has a different Python version's incompatible marshal format), raise :exc:`EOFError`, :exc:`ValueError` or :exc:`TypeError`. :ref:`Code objects <code-objects>` are only supported if *allow_code* is true. The file must be a readable :term:`binary file`.
If an object containing an unsupported type was marshalled with :func:`dump`, :func:`load` will substitute ``None`` for the unmarshallable type.
This call used to raise a ``code.__new__`` audit event for each code object. Now it raises a single ``marshal.load`` event for the entire load operation.
Return the bytes object that would be written to a file by ``dump(value, file)``. The value must be a supported type. Raise a :exc:`ValueError` exception if value has (or contains an object that has) an unsupported type. :ref:`Code objects <code-objects>` are only supported if *allow_code* is true.
Convert the :term:`bytes-like object` to a value. If no valid value is found, raise :exc:`EOFError`, :exc:`ValueError` or :exc:`TypeError`. :ref:`Code objects <code-objects>` are only supported if *allow_code* is true. Extra bytes in the input are ignored.
This call used to raise a ``code.__new__`` audit event for each code object. Now it raises a single ``marshal.loads`` event for the entire load operation.
Support for object instancing and recursion
Support for :class:`slice` objects
Support for :class:`frozendict` objects
object
objek
code object
objek kode