日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:文件對(duì)象

文件對(duì)象

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 (FILE*) support from the C standard library. In Python 3, files and streams use the new 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 io APIs instead.

法庫網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站,法庫網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為法庫成百上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的法庫做網(wǎng)站的公司定做!

PyObject *PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const char *encoding, const char *errors, const char *newline, int closefd)

Return value: New reference. Part of the Stable ABI.

根據(jù)已打開文件 fd 的文件描述符創(chuàng)建一個(gè) Python 文件對(duì)象。 參數(shù) name, encoding, errorsnewline 可以為 NULL 表示使用默認(rèn)值;buffering 可以為 -1 表示使用默認(rèn)值。 name 會(huì)被忽略僅保留用于向下兼容。 失敗時(shí)返回 NULL。 有關(guān)參數(shù)的更全面描述,請(qǐng)參閱 io.open() 函數(shù)的文檔。

警告

由于Python流具有自己的緩沖層,因此將它們與 OS 級(jí)文件描述符混合會(huì)產(chǎn)生各種問題(例如數(shù)據(jù)的意外排序)。

在 3.2 版更改: 忽略 name 屬性。

int PyObject_AsFileDescriptor(PyObject *p)

Part of the Stable ABI.

Return the file descriptor associated with p as an int. If the object is an integer, its value is returned. If not, the object’s 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.

PyObject *PyFile_GetLine(PyObject *p, int n)

Return value: New reference. Part of the Stable ABI.

等價(jià)于 p.readline([n]) ,這個(gè)函數(shù)從對(duì)象 p 中讀取一行。 p 可以是文件對(duì)象或具有 readline() 方法的任何對(duì)象。 如果 n0 ,則無論該行的長度如何,都會(huì)讀取一行。 如果 n 大于``0``,則從文件中讀取不超過 n 個(gè)字節(jié);可以返回行的一部分。 在這兩種情況下,如果立即到達(dá)文件末尾,則返回空字符串。 但是,如果 n 小于 0 ,則無論長度如何都會(huì)讀取一行,但是如果立即到達(dá)文件末尾,則引發(fā) EOFError。

int PyFile_SetOpenCodeHook(Py_OpenCodeHookFunction handler)

重載 io.open_code() 的正常行為,將其形參通過所提供的處理程序來傳遞。

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

userData 指針會(huì)被傳入鉤子函數(shù)。 因于鉤子函數(shù)可能由不同的運(yùn)行時(shí)調(diào)用,該指針不應(yīng)直接指向 Python 狀態(tài)。

鑒于這個(gè)鉤子專門在導(dǎo)入期間使用的,請(qǐng)避免在新模塊執(zhí)行期間進(jìn)行導(dǎo)入操作,除非已知它們?yōu)閮鼋Y(jié)狀態(tài)或者是在 sys.modules 中可用。

一旦鉤子被設(shè)定,它就不能被移除或替換,之后對(duì) PyFile_SetOpenCodeHook() 的調(diào)用也將失敗,如果解釋器已經(jīng)被初始化,函數(shù)將返回 -1 并設(shè)置一個(gè)異常。

此函數(shù)可以安全地在 Py_Initialize() 之前調(diào)用。

引發(fā)一個(gè) 審計(jì)事件 setopencodehook,不附帶任何參數(shù)。

3.8 新版功能.

int PyFile_WriteObject(PyObject *obj, PyObject *p, int flags)

Part of the Stable ABI.

將對(duì)象 obj 寫入文件對(duì)象 pflags 唯一支持的標(biāo)志是 Py_PRINT_RAW;如果給定,則寫入對(duì)象的 str() 而不是 repr()。成功時(shí)返回 0,失敗時(shí)返回 -1。 將設(shè)置適當(dāng)?shù)睦狻?/p>

int PyFile_WriteString(const char *s, PyObject *p)

Part of the Stable ABI.

將字符串 s 寫入文件對(duì)象 p。 成功返回 0 失敗返回 -1;將設(shè)定相應(yīng)的異常。


網(wǎng)站名稱:創(chuàng)新互聯(lián)Python教程:文件對(duì)象
本文鏈接:http://www.dlmjj.cn/article/dpohipp.html