अजगर में आप एक फ़ाइल वस्तु की readlines
विधि का उपयोग कर सकते हैं।
with open('topsites.txt') as f:
testsite_array=f.readlines()
या बस list
उपयोग करते हैं, इस readlines
का उपयोग कर के रूप में ही है, लेकिन फर्क सिर्फ इतना है कि हम readlines
के लिए एक वैकल्पिक आकार तर्क पारित सकता है:
with open('topsites.txt') as f:
testsite_array=list(f)
मदद पर 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.
स्रोत
2013-04-25 19:17:39