Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Document PyFile_OpenCode() and PyFile_OpenCodeObject().
  • Loading branch information
ZeroIntensity committed Nov 11, 2025
commit a52e9495f4fe77bf39654ef102ebac99ff994340
25 changes: 25 additions & 0 deletions Doc/c-api/file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ the :mod:`io` APIs instead.
.. versionadded:: 3.8


.. c:function:: PyObject *PyFile_OpenCodeObject(PyObject *path)

Open *path* and read the text. *path* must be a Python :class:`str`
Comment thread
ZeroIntensity marked this conversation as resolved.
Outdated
object. The behavior of this function may be overridden by
:c:func:`PyFile_SetOpenCodeHook` to allow for some preprocessing of the
text.

This is analogous to :func:`io.open_code` in Python.
Comment thread
StanFromIreland marked this conversation as resolved.

On success, this function returns a :term:`strong reference` to a Python
file object. On failure, this function returns ``NULL`` with an exception
set.

.. versionadded:: 3.8


.. c:function:: PyObject *PyFile_OpenCode(const char *path)

Similar to :c:func:`PyFile_OpenCodeObject`, but *path* is a
:c:expr:`const char*` that is decoded by the
:term:`filesystem encoding and error handler`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UTF-8 encoding, no (also implied by the parameter name)?

PyObject *pathobj = PyUnicode_FromString(utf8path);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch.


.. versionadded:: 3.8


.. c:function:: int PyFile_WriteObject(PyObject *obj, PyObject *p, int flags)

Expand All @@ -108,3 +132,4 @@ the :mod:`io` APIs instead.

Write string *s* to file object *p*. Return ``0`` on success or ``-1`` on
failure; the appropriate exception will be set.