Class TextFile
Text files with line iteration and transparent compression
TextFile instances can be used like normal file objects (i.e. by
calling read(), readline(), readlines(), and write()), but can also be
used as sequences of lines in for-loops.
TextFile objects also handle compression transparently. i.e. it is
possible to read lines from a compressed text file as if it were not
compressed. Compression is deduced from the file name suffixes '.Z'
(compress/uncompress), '.gz' (gzip/gunzip), and '.bz2' (bzip2).
Finally, TextFile objects accept file names that start with '~' or
'~user' to indicate a home directory, as well as URLs (for reading
only).
__init__(self,
filename,
mode=' r ' )
(Constructor)
|
|
- Parameters:
filename (str ) - file name or URL
mode (str ) - file access mode: 'r' (read), 'w' (write), or 'a' (append)
|