in Python è possibile utilizzare il metodo di un oggetto file readlines
.
with open('topsites.txt') as f:
testsite_array=f.readlines()
o semplicemente utilizzare list
, questo è lo stesso come utilizzare readlines
ma l'unica differenza è che possiamo passare un argomento opzionale dimensioni a readlines
:
with open('topsites.txt') as f:
testsite_array=list(f)
aiuto su file.readlines
:
In [46]: file.readlines?
Type: method_descriptor
String Form:<method 'readlines' of 'file' objects>
Namespace: Python builtin
Docstring:
readlines([size]) -> list of strings, each a line from the file.
Call readline() repeatedly and return a list of the lines so read.
The optional size argument, if given, is an approximate bound on the
total number of bytes in the lines returned.
fonte
2013-04-25 19:17:39