MCPcopy Index your code
hub / github.com/python/cpython / truncate

Method truncate

Lib/_pyio.py:1790–1802  ·  view source on GitHub ↗

Truncate the file to at most size bytes. Size defaults to the current file position, as returned by tell(). The current file position is changed to the value of size.

(self, size=None)

Source from the content-addressed store, hash-verified

1788 return os.lseek(self._fd, 0, SEEK_CUR)
1789
1790 def truncate(self, size=None):
1791 """Truncate the file to at most size bytes.
1792
1793 Size defaults to the current file position, as returned by tell().
1794 The current file position is changed to the value of size.
1795 """
1796 self._checkClosed()
1797 self._checkWritable()
1798 if size is None:
1799 size = self.tell()
1800 os.ftruncate(self._fd, size)
1801 self._stat_atopen = None
1802 return size
1803
1804 def close(self):
1805 """Close the file.

Callers 2

testTruncateMethod · 0.95
bug801631Method · 0.95

Calls 3

_checkWritableMethod · 0.95
tellMethod · 0.95
_checkClosedMethod · 0.45

Tested by 2

testTruncateMethod · 0.76
bug801631Method · 0.76