本文介紹了readlines() 在 Python 3 中是否返回列表或迭代器?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我讀過深入 Python 3".那:
I've read in "Dive into Python 3" that:
readlines()
方法現在返回一個迭代器,因此它與 Python 2 中的 xreadlines()
一樣高效".em>
"The
readlines()
method now returns an iterator, so it is just as efficient asxreadlines()
was in Python 2".
參見:附錄 A:移植代碼使用 2to3 到 Python 3:A.26 xreadlines() I/O 方法.
我不確定這是不是真的,因為他們在這里沒有提到:http://docs.python.org/release/3.0.1/whatsnew/3.0.html .如何檢查?
I'm not sure that's true because they don't mention it here: http://docs.python.org/release/3.0.1/whatsnew/3.0.html . How can I check that?
推薦答案
像這樣:
Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('/junk/so/foo.txt')
>>> type(f.readlines())
<class 'list'>
>>> help(f.readlines)
Help on built-in function readlines:
readlines(...)
Return a list of lines from the stream.
hint can be specified to control the number of lines read: no more
lines will be read if the total size (in bytes/characters) of all
lines so far exceeds hint.
>>>
這篇關于readlines() 在 Python 3 中是否返回列表或迭代器?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!