Seeks to the offset in the file. 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 usuall
(self, offset=None, whence=0, position=None)
| 131 | None, "position is deprecated in favor of the offset argument.", |
| 132 | "position") |
| 133 | def seek(self, offset=None, whence=0, position=None): |
| 134 | # TODO(jhseu): Delete later. Used to omit `position` from docs. |
| 135 | # pylint: disable=g-doc-args |
| 136 | """Seeks to the offset in the file. |
| 137 | |
| 138 | Args: |
| 139 | offset: The byte count relative to the whence argument. |
| 140 | whence: Valid values for whence are: |
| 141 | 0: start of the file (default) |
| 142 | 1: relative to the current position of the file |
| 143 | 2: relative to the end of file. offset is usually negative. |
| 144 | """ |
| 145 | # pylint: enable=g-doc-args |
| 146 | self._preread_check() |
| 147 | # We needed to make offset a keyword argument for backwards-compatibility. |
| 148 | # This check exists so that we can convert back to having offset be a |
| 149 | # positional argument. |
| 150 | # TODO(jhseu): Make `offset` a positional argument after `position` is |
| 151 | # deleted. |
| 152 | if offset is None and position is None: |
| 153 | raise TypeError("seek(): offset argument required") |
| 154 | if offset is not None and position is not None: |
| 155 | raise TypeError("seek(): offset and position may not be set " |
| 156 | "simultaneously.") |
| 157 | |
| 158 | if position is not None: |
| 159 | offset = position |
| 160 | |
| 161 | with errors.raise_exception_on_not_ok_status() as status: |
| 162 | if whence == 0: |
| 163 | pass |
| 164 | elif whence == 1: |
| 165 | offset += self.tell() |
| 166 | elif whence == 2: |
| 167 | offset += self.size() |
| 168 | else: |
| 169 | raise errors.InvalidArgumentError( |
| 170 | None, None, |
| 171 | "Invalid whence argument: {}. Valid values are 0, 1, or 2.".format( |
| 172 | whence)) |
| 173 | ret_status = self._read_buf.Seek(offset) |
| 174 | pywrap_tensorflow.Set_TF_Status_from_Status(status, ret_status) |
| 175 | |
| 176 | def readline(self): |
| 177 | r"""Reads the next line from the file. Leaves the '\n' at the end.""" |