¡Reserva! Google I / O regresa del 18 al 20 de mayo Regístrese ahora


File I/O wrappers without thread locking.

Used in the notebooks

Used in the tutorials

The main roles of the tf.io.gfile module are:

  1. To provide an API that is close to Python's file I/O objects, and
  2. To provide an implementation based on TensorFlow's C++ FileSystem API.

The C++ FileSystem API supports multiple file system implementations, including local files, Google Cloud Storage (using a gs:// prefix, and HDFS (using an hdfs:// prefix). TensorFlow exports these as tf.io.gfile, so that you can use these implementations for saving and loading checkpoints, writing to TensorBoard logs, and accessing training data (among other uses). However, if all your files are local, you can use the regular Python file API without any problem.

mode Returns the mode in which the file was opened.
name Returns the file name.



View source

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


View source

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.


View source


View source

Returns the contents of a file as a string.

Starts reading from current position in file.

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

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


View source

Reads the next line, keeping \n. At EOF, returns ''.


View source

Returns all lines from the file in a list.


View source

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

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.


View source

Returns True as FileIO supports random access ops of seek()/tell()


View source

Returns the size of the file.


View source

Returns the current position in the file.


View source

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


View source

Make usable with "with" statement.


View source

Make usable with "with" statement.


View source