The file-like types which wraps/proxies an other file objects.
The complete proxy for wrapped file-like object.
Parameters: | wrapped (file, file-like object) – the file object to wrap |
---|
Closes the file. It’s a context manager as well, so prefer with statement than direct call of this:
with FileProxy(file_) as f:
print f.read()
Implementation of collections.Iterator protocol.
Reads at the most size bytes from the file. It maybe less if the read hits EOF before obtaining size bytes.
Parameters: | size – bytes to read. if it is negative or omitted, read all data until EOF is reached. default is -1 |
---|---|
Returns: | read bytes. an empty string when EOF is encountered immediately |
Return type: | str |
Reads an entire line from the file. A trailing newline character is kept in the string (but maybe absent when a file ends with an incomplete line).
Parameters: | size (numbers.Integral) – if it’s present and non-negative, it is maximum byte count (including trailing newline) and an incomplete line maybe returned |
---|---|
Returns: | read bytes |
Return type: | str |
Note
Unlike stdio‘s fgets(), the returned string contains null characters ('\0') if they occurred in the input.
Reads until EOF using readline().
Parameters: | sizehint (numbers.Integral) – if it’s present, instead of reading up to EOF, whole lines totalling approximately sizehint bytes (or more to accommodate a final whole line) |
---|---|
Returns: | a list containing the lines read |
Return type: | list |
It memorizes the current position (tell()) when the context enters and then rewinds (seek()) back to the memorized initial_offset when the context exits.
The almost same to FileProxy except it has seek() and tell() methods in addition.
Sets the file’s current position.
Parameters: |
|
---|
Gets the file’s current position.
Returns: | the file’s current position |
---|---|
Return type: | numbers.Integral |