10 examples of 'python file seek' in Python

Every line of 'python file seek' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
195def test__FileIO_seek(self):
196 '''
197 TODO
198 '''
199 pass
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

94def _seek(self, *args, **kwargs):
95 return self.inp.seek(*args, **kwargs)
82def seek(self, offset, whence=0):
83 """Seek to an offset in the file."""
84 if self.fh:
85 self.fh.seek(offset, whence)
86 else:
87 raise RuntimeError('Unable to seek into a file that is not open.')
63def seek(self, pos, whence=0):
64 if whence == 0:
65 self._from_end = False
66 self._offset = pos
67 elif whence == 1:
68 self._offset += pos
69 elif whence == 2:
70 self._from_end = True
71 self._offset = pos
72 else:
73 raise ValueError("seek() second argument must be 0, 1 or 2")
18def seek(self, offset, whence=Undefined): pass
188def seek(self, offset, whence=os.SEEK_SET):
189 """Seek into a specific location in a file.
190
191 This method implements a simple method to seek into a
192 compressed file from the end, which is not implemented by the
193 gzip library.
194
195 Args:
196 offset: An integer, indicating the number of bytes to seek in file,
197 how that value is interpreted depends on the 'whence' value.
198 whence: An integer; 0 means from beginning, 1 from last position
199 and 2 indicates we are about to seek from the end of the file.
200
201 Raises:
202 RuntimeError: If a seek is attempted to a closed file.
203 """
204 if not self._gzip_file:
205 raise RuntimeError('Unable to seek into a file that is not open.')
206
207 if whence == 2:
208 ofs = self._gzip_file.size + offset
209 if ofs > self._gzip_file.tell():
210 self._gzip_file.seek(ofs - self._gzip_file.offset, 1)
211 else:
212 self._gzip_file.rewind()
213 self._gzip_file.seek(ofs)
214 else:
215 self._gzip_file.seek(offset, whence)
266def seek(self, offset, whence=os.SEEK_SET):
267 """Seek to an offset in the file."""
268 self._file_object.seek(offset, whence)
181def test_seek(self, space, tmpdir):
182 f = tmpdir.join("file.txt")
183 f.write("content")
184 w_res = space.execute("""
185 res = []
186 f = File.new('%s', "r+")
187 f.seek(2, IO::SEEK_SET)
188 res << f.read
189 f.seek(2)
190 res << f.read
191 f.seek(-3, IO::SEEK_CUR)
192 res << f.read
193 f.seek(-2, IO::SEEK_END)
194 res << f.read
195 return res
196 """ % f)
197 assert self.unwrap(space, w_res) == [
198 "ntent", "ntent", "ent", "nt"
199 ]
200 with self.raises(space, "IOError", "closed stream"):
201 space.execute("""
202 io = File.new('%s')
203 io.close
204 io.seek 2
205 """ % f)
345def seek(self, pos, mode = 0):
346 pass
168def seek(self, offset, whence=0):
169 if whence == 0:
170 self._offset = offset
171 elif whence == 1:
172 self._offset += offset
173 elif whence == 2:
174 self._offset = self._size + offset
175 else:
176 err = f"ValueError: invalid whence ({whence}, should be 0, 1 or 2)"
177 raise ValueError(err)

Related snippets