tf.gfile.FastGFile

Class FastGFile

Defined in tensorflow/python/platform/gfile.py.

File I/O wrappers without thread locking.

Note, that this is somewhat like builtin Python file I/O, but there are semantic differences to make it more efficient for some backing filesystems. For example, a write mode file will not be opened until the first write call (to minimize RPC invocations in network filesystems).

__init__

__init__(
    name,
    mode='r'
)

DEPRECATED FUNCTION

Properties

mode

Returns the mode in which the file was opened.

name

Returns the file name.

Methods

tf.gfile.FastGFile.__enter__

__enter__()

Make usable with "with" statement.

tf.gfile.FastGFile.__exit__

__exit__(
    unused_type,
    unused_value,
    unused_traceback
)

Make usable with "with" statement.

tf.gfile.FastGFile.__iter__

__iter__()

tf.gfile.FastGFile.__next__

__next__()

tf.gfile.FastGFile.close

close()

Closes FileIO. Should be called for the WritableFile to be flushed.

tf.gfile.FastGFile.flush

flush()

Flushes the Writable file.

This only ensures that the data has made its way out of the process without any guarantees on whether it's written to disk. This means that the data would survive an application crash but not necessarily an OS crash.

tf.gfile.FastGFile.next

next()

tf.gfile.FastGFile.read

read(n=-1)

Returns the contents of a file as a string.

Starts reading from current position in file.

Args:

  • n: Read 'n' bytes if n != -1. If n = -1, reads to end of file.

Returns:

'n' bytes of the file (or whole file) in bytes mode or 'n' bytes of the string if in string (regular) mode.

tf.gfile.FastGFile.readline

readline()

Reads the next line from the file. Leaves the '\n' at the end.

tf.gfile.FastGFile.readlines

readlines()

Returns all lines from the file in a list.

tf.gfile.FastGFile.seek

seek(
    offset=None,
    whence=0,
    position=None
)

Seeks to the offset in the file. (deprecated arguments)

Args:

  • offset: The byte count relative to the whence argument.
  • whence: Valid values for whence are:
  • 0: start of the file (default)
  • 1: relative to the current position of the file
  • 2: relative to the end of file. offset is usually negative.

tf.gfile.FastGFile.size

size()

Returns the size of the file.

tf.gfile.FastGFile.tell

tell()

Returns the current position in the file.

tf.gfile.FastGFile.write

write(file_content)

Writes file_content to the file. Appends to the end of the file.