Package grizzled :: Package io :: Class AutoFlush
[hide private]
[frames] | no frames]

Class AutoFlush

source code

object --+
         |
        AutoFlush

An AutoFlush wraps a file-like object and flushes the output (via a call to flush() after every write operation. Here's how to use an AutoFlush object to force standard output to flush after every write:

import sys
from grizzled.io import AutoFlush

sys.stdout = AutoFlush(sys.stdout)
Instance Methods [hide private]
 
__init__(self, f)
Create a new AutoFlush object to wrap a file-like object.
source code
 
write(self, buf)
Write the specified buffer to the file.
source code
 
flush(self)
Force a flush.
source code
 
truncate(self, size=-1)
Truncate the underlying file.
source code
int
tell(self)
Return the file's current position, if applicable.
source code
 
seek(self, offset, whence=0)
Set the file's current position.
source code
int
fileno(self)
Return the integer file descriptor used by the underlying file.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, f)
(Constructor)

source code 
Create a new AutoFlush object to wrap a file-like object.
Parameters:
  • f (file) - A file-like object that contains both a write() method and a flush() method.
Overrides: object.__init__

write(self, buf)

source code 
Write the specified buffer to the file.
Parameters:
  • buf (str or bytes) - buffer to write

truncate(self, size=-1)

source code 
Truncate the underlying file. Might fail.
Parameters:
  • size (int) - Where to truncate. If less than 0, then file's current position is used.

tell(self)

source code 
Return the file's current position, if applicable.
Returns: int
Current file position

seek(self, offset, whence=0)

source code 

Set the file's current position. The whence argument is optional; legal values are:

  • os.SEEK_SET or 0: absolute file positioning (default)
  • os.SEEK_CUR or 1: seek relative to the current position
  • os.SEEK_END or 2: seek relative to the file's end

There is no return value. Note that if the file is opened for appending (mode 'a' or 'a+'), any seek() operations will be undone at the next write. If the file is only opened for writing in append mode (mode 'a'), this method is essentially a no-op, but it remains useful for files opened in append mode with reading enabled (mode 'a+'). If the file is opened in text mode (without 'b'), only offsets returned by tell() are legal. Use of other offsets causes undefined behavior.

Note that not all file objects are seekable.

Parameters:
  • offset (int) - where to seek
  • whence (int) - see above

fileno(self)

source code 
Return the integer file descriptor used by the underlying file.
Returns: int
the file descriptor