Pelokalan
Python ID
id en
Masuk
Proyek
library__sys.po Berkas proyek · python-docs-id-3.14 · Bahasa Indonesia
Modul PO Hanya lihat
Teks sumber — English
Terjemahan — Bahasa Indonesia
An object containing information about the ABI of the currently running Python interpreter. It should include information that affect the CPython ABI in ways that require a specific build of the interpreter chosen from variants that can co-exist on a single machine. For example, it does not encode the base OS (Linux or Windows), but does include pointer size since some systems support both 32- and 64-bit builds. The available entries are the same on all platforms; e.g. *pointer_size* is available even on 64-bit-only architectures.
When an exception other than :exc:`SystemExit` is raised and uncaught, the interpreter calls ``sys.excepthook`` with three arguments, the exception class, exception instance, and a traceback object. In an interactive session this happens just before control is returned to the prompt; in a Python program this happens just before the program exits. The handling of such top-level exceptions can be customized by assigning another three-argument function to ``sys.excepthook``.
These objects contain the original values of ``breakpointhook``, ``displayhook``, ``excepthook``, and ``unraisablehook`` at the start of the program. They are saved so that ``breakpointhook``, ``displayhook`` and ``excepthook``, ``unraisablehook`` can be restored in case they happen to get replaced with broken or alternative objects.
This function returns the old-style representation of the handled exception. If an exception ``e`` is currently handled (so :func:`exception` would return ``e``), :func:`exc_info` returns the tuple ``(type(e), e, e.__traceback__)``. That is, a tuple containing the type of the exception (a subclass of :exc:`BaseException`), the exception itself, and a :ref:`traceback object <traceback-objects>` which typically encapsulates the call stack at the point where the exception last occurred.
The optional argument *arg* can be an integer giving the exit status (defaulting to zero), or another type of object. If it is an integer, zero is considered "successful termination" and any nonzero value is considered "abnormal termination" by shells and the like. Most systems require it to be in the range 0--127, and produce undefined results otherwise. Some systems have a convention for assigning specific meanings to specific exit codes, but these are generally underdeveloped; Unix programs generally use 2 for command line syntax errors and 1 for all other kinds of errors. If another type of object is passed, ``None`` is equivalent to passing zero, and any other object is printed to :data:`stderr` and results in an exit code of 1. In particular, ``sys.exit("some error message")`` is a quick way to exit a program when an error occurs.
Return the number of unicode objects that have been interned.
Return the reference count of the *object*. The count returned is generally one higher than you might expect, because it includes the (temporary) reference as an argument to :func:`getrefcount`.
Note that the returned value may not actually reflect how many references to the object are actually held. For example, some objects are :term:`immortal` and have a very high refcount that does not reflect the actual number of references. Consequently, do not rely on the returned value to be accurate, other than a value of 0 or 1.
:term:`Immortal <immortal>` objects with a large reference count can be identified via :func:`_is_immortal`.
Immortal objects have very large refcounts that do not match the actual number of references to the object.
Return the size of an object in bytes. The object can be any type of object. All built-in objects will return correct results, but this does not have to hold true for third-party extensions as it is implementation specific.
Only the memory consumption directly attributed to the object is accounted for, not the memory consumption of objects it refers to.
If given, *default* will be returned if the object does not provide means to retrieve the size. Otherwise a :exc:`TypeError` will be raised.
:func:`getsizeof` calls the object's ``__sizeof__`` method and adds an additional garbage collector overhead if the object is managed by the garbage collector.
See `recursive sizeof recipe <https://code.activestate.com/recipes/577504-compute-memory-footprint-of-an-object-and-its-cont/>`_ for an example of using :func:`getsizeof` recursively to find the size of containers and all their contents.
Return a frame object from the call stack. If optional integer *depth* is given, return the frame object that many calls below the top of the stack. If that is deeper than the call stack, :exc:`ValueError` is raised. The default for *depth* is zero, returning the frame at the top of the call stack.
Return a list of up to *limit* dynamically allocated Python objects. If *type* is given, only objects of that exact type (not subtypes) are included.
Objects from the list are not safe to use. Specifically, the result will include objects from all interpreters that share their object allocator state (that is, ones created with :c:member:`PyInterpreterConfig.use_main_obmalloc` set to 1 or using :c:func:`Py_NewInterpreter`, and the :ref:`main interpreter <sub-interpreter-support>`). Mixing objects from different interpreters may lead to crashes or other unexpected behavior.
The result may include objects from other interpreters.
Returns an *asyncgen_hooks* object, which is similar to a :class:`~collections.namedtuple` of the form ``(firstiter, finalizer)``, where *firstiter* and *finalizer* are expected to be either ``None`` or functions which take an :term:`asynchronous generator iterator` as an argument, and are used to schedule finalization of an asynchronous generator by an event loop.
An object containing information about the implementation of the currently running Python interpreter. The following attributes are required to exist in all Python implementations.
Raises an :ref:`auditing event <auditing>` ``cpython.run_interactivehook`` with the hook object as the argument when the hook is called on startup.
Return :const:`True` if the given object is :term:`immortal`, :const:`False` otherwise.
Objects that are immortal (and thus return ``True`` upon being passed to this function) are not guaranteed to be immortal in future versions, and vice versa for mortal objects.
A list of :term:`meta path finder` objects that have their :meth:`~importlib.abc.MetaPathFinder.find_spec` methods called to see if one of the objects can find the module to be imported. By default, it holds entries that implement Python's default import semantics. The :meth:`~importlib.abc.MetaPathFinder.find_spec` method is called with at least the absolute name of the module being imported. If the module to be imported is contained in a package, then the parent package's :attr:`~module.__path__` attribute is passed in as a second argument. The method returns a :term:`module spec`, or ``None`` if the module cannot be found.
The abstract base class defining the interface of finder objects on :data:`meta_path`.
A dictionary acting as a cache for :term:`finder` objects. The keys are paths that have been passed to :data:`sys.path_hooks` and the values are the finders that are found. If a path is a valid file system path but no finder is found on :data:`sys.path_hooks` then ``None`` is stored.
Strings specifying the primary and secondary prompt of the interpreter. These are only defined if the interpreter is in interactive mode. Their initial values in this case are ``'>>> '`` and ``'... '``. If a non-string object is assigned to either variable, its :func:`str` is re-evaluated each time the interpreter prepares to read a new interactive command; this can be used to implement a dynamic prompt.
A C function is about to be called. This may be an extension function or a built-in. *arg* is the C function object.
A C function has returned. *arg* is the C function object.
A C function has raised an exception. *arg* is the C function object.
Trace functions should have three arguments: *frame*, *event*, and *arg*. *frame* is the :ref:`current stack frame <frame-objects>`. *event* is a string: ``'call'``, ``'line'``, ``'return'``, ``'exception'`` or ``'opcode'``. *arg* depends on the event type.
The interpreter is about to execute a new line of code or re-execute the condition of a loop. The local trace function is called; *arg* is ``None``; the return value specifies the new local trace function. See :source:`InternalDocs/code_objects.md` for a detailed explanation of how this works. Per-line events may be disabled for a frame by setting :attr:`~frame.f_trace_lines` to :const:`False` on that :ref:`frame <frame-objects>`.
The interpreter is about to execute a new opcode (see :mod:`dis` for opcode details). The local trace function is called; *arg* is ``None``; the return value specifies the new local trace function. Per-opcode events are not emitted by default: they must be explicitly requested by setting :attr:`~frame.f_trace_opcodes` to :const:`True` on the :ref:`frame <frame-objects>`.
For more information on code and frame objects, refer to :ref:`types`.
Allows enabling or disabling coroutine origin tracking. When enabled, the ``cr_origin`` attribute on coroutine objects will contain a tuple of (filename, line number, function name) tuples describing the traceback where the coroutine object was created, with the most recent call first. When disabled, ``cr_origin`` will be ``None``.
:term:`File objects <file object>` used by the interpreter for standard input, output and errors:
To write or read binary data from/to the standard streams, use the underlying binary :data:`~io.TextIOBase.buffer` object. For example, to write bytes to :data:`stdout`, use ``sys.stdout.buffer.write(b'abc')``.
However, if you are writing a library (and do not control in which context its code will be executed), be aware that the standard streams may be replaced with file-like objects like :class:`io.StringIO` which do not support the :attr:`!buffer` attribute.
These objects contain the original values of ``stdin``, ``stderr`` and ``stdout`` at the start of the program. They are used during finalization, and could be useful to print to the actual standard stream no matter if the ``sys.std*`` object has been redirected.
It can also be used to restore the actual files to known working file objects in case they have been overwritten with a broken object. However, the preferred way to do this is to explicitly save the previous stream before replacing it, and restore the saved object.
:attr:`!object`: Object causing the exception, can be ``None``.
The default hook formats :attr:`!err_msg` and :attr:`!object` as: ``f'{err_msg}: {object!r}'``; use "Exception ignored in" error message if :attr:`!err_msg` is ``None``. Similar to the :mod:`traceback` module, this adds color to exceptions by default. This can be disabled using :ref:`environment variables <using-on-controlling-color>`.
Storing :attr:`!object` using a custom hook can resurrect it if it is set to an object which is being finalized. Avoid storing :attr:`!object` after the custom hook completes to avoid resurrecting objects.
Raise an auditing event ``sys.unraisablehook`` with arguments *hook*, *unraisable* when an exception that cannot be handled occurs. The *unraisable* object is the same as what will be passed to the hook. If no hook has been set, *hook* may be ``None``.
object
objek