开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

source-code-analysis/python3.8.1

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
python3.8.1
/
Doc
/
c-api
/
file.rst
python3.8.1
/
Doc
/
c-api
/
file.rst
file.rst 4.18 KB
一键复制 编辑 原始数据 按行查看 历史
zhangweibo 提交于 2021年11月16日 09:46 +08:00 . git init

File Objects

.. index:: object: file

These APIs are a minimal emulation of the Python 2 C API for built-in file objects, which used to rely on the buffered I/O (:c:type:`FILE\*`) support from the C standard library. In Python 3, files and streams use the new :mod:`io` module, which defines several layers over the low-level unbuffered I/O of the operating system. The functions described below are convenience C wrappers over these new APIs, and meant mostly for internal error reporting in the interpreter; third-party code is advised to access the :mod:`io` APIs instead.

.. c:function:: PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const char *encoding, const char *errors, const char *newline, int closefd)

 Create a Python file object from the file descriptor of an already
 opened file *fd*. The arguments *name*, *encoding*, *errors* and *newline*
 can be ``NULL`` to use the defaults; *buffering* can be *-1* to use the
 default. *name* is ignored and kept for backward compatibility. Return
 ``NULL`` on failure. For a more comprehensive description of the arguments,
 please refer to the :func:`io.open` function documentation.

 .. warning::

 Since Python streams have their own buffering layer, mixing them with
 OS-level file descriptors can produce various issues (such as unexpected
 ordering of data).

 .. versionchanged:: 3.2
 Ignore *name* attribute.


.. c:function:: int PyObject_AsFileDescriptor(PyObject *p)

 Return the file descriptor associated with *p* as an :c:type:`int`. If the
 object is an integer, its value is returned. If not, the
 object's :meth:`~io.IOBase.fileno` method is called if it exists; the
 method must return an integer, which is returned as the file descriptor
 value. Sets an exception and returns ``-1`` on failure.


.. c:function:: PyObject* PyFile_GetLine(PyObject *p, int n)

 .. index:: single: EOFError (built-in exception)

 Equivalent to ``p.readline([n])``, this function reads one line from the
 object *p*. *p* may be a file object or any object with a
 :meth:`~io.IOBase.readline`
 method. If *n* is ``0``, exactly one line is read, regardless of the length of
 the line. If *n* is greater than ``0``, no more than *n* bytes will be read
 from the file; a partial line can be returned. In both cases, an empty string
 is returned if the end of the file is reached immediately. If *n* is less than
 ``0``, however, one line is read regardless of length, but :exc:`EOFError` is
 raised if the end of the file is reached immediately.


.. c:function:: int PyFile_SetOpenCodeHook(Py_OpenCodeHookFunction handler)

 Overrides the normal behavior of :func:`io.open_code` to pass its parameter
 through the provided handler.

 The handler is a function of type :c:type:`PyObject *(\*)(PyObject *path,
 void *userData)`, where *path* is guaranteed to be :c:type:`PyUnicodeObject`.

 The *userData* pointer is passed into the hook function. Since hook
 functions may be called from different runtimes, this pointer should not
 refer directly to Python state.

 As this hook is intentionally used during import, avoid importing new modules
 during its execution unless they are known to be frozen or available in
 ``sys.modules``.

 Once a hook has been set, it cannot be removed or replaced, and later calls to
 :c:func:`PyFile_SetOpenCodeHook` will fail. On failure, the function returns
 -1 and sets an exception if the interpreter has been initialized.

 This function is safe to call before :c:func:`Py_Initialize`.

 .. versionadded:: 3.8



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

 .. index:: single: Py_PRINT_RAW

 Write object *obj* to file object *p*. The only supported flag for *flags* is
 :const:`Py_PRINT_RAW`; if given, the :func:`str` of the object is written
 instead of the :func:`repr`. Return ``0`` on success or ``-1`` on failure; the
 appropriate exception will be set.


.. c:function:: int PyFile_WriteString(const char *s, PyObject *p)

 Write string *s* to file object *p*. Return ``0`` on success or ``-1`` on
 failure; the appropriate exception will be set.
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

暂无描述
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/python_sourcecode/python3.8.1.git
git@gitee.com:python_sourcecode/python3.8.1.git
python_sourcecode
python3.8.1
python3.8.1
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /