Skip to Content
Python 技術手冊 第三版
book

Python 技術手冊 第三版

by lex Martelli, Anna Martelli Ravenscroft, Steve Holden
January 2018
Intermediate to advanced
856 pages
17h 17m
Chinese
GoTop Information, Inc.
Content preview from Python 技術手冊 第三版
檔案 I/O 的輔助模組
|
323
檔案 I/O 的輔助模組
「檔案」物件提供檔案 I/O 所需的最底限功能性,而某些輔助用的 Python
程式庫模組則提供便利的補充功能性,在幾種重要的情況中,讓 I/O 變得
更加容易且方便。
fileinput 模組
fileinput
模組讓你以迴圈處理文字檔案所成的一個串列(a list of text
files)中的所有文字行。效能良好,堪比在每個檔案上直接迭代的效能,
因為用了緩衝來最小化 I/O。因此,只要你覺得該模組豐富的功能性很方
便,你就能將模組
fileinput
用於資料行導向(line-oriented)的輸入,而
不用擔心效能。
input
函式是模組
fileinput
的關鍵函式;該模組也提供一
FileInput
類別,其方法提供與該模組的函式相同的功能性。該模組的內
容列於此:
close close()
關閉整個序列,讓迭代停止,並且沒有檔案仍然開啟。
FileInput class FileInput(files=None, inplace=False, backup='', bufsize=0,
openhook=None)
創建並回傳類別
FileInput
的一個實體
f
。引數與
fileinput.input
相同,
f
的方法與模組
fileinput
的函式有相同的名稱、引數和語意。
f
也提
供方法
readline
,它會讀取並回傳下一行。當你想要內嵌或混合會從多個
檔案序列讀取資料行的迴圈,你就可以明確地使用類別
FileInput
filelineno ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

利用 Python 进行数据分析(原书第2版)

利用 Python 进行数据分析(原书第2版)

Wes McKinney

Publisher Resources

ISBN: 9789864766819