MCPcopy Index your code
hub / github.com/RustPython/RustPython / truncate

Method truncate

Lib/_pyio.py:1769–1781  ·  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

1767 return os.lseek(self._fd, 0, SEEK_CUR)
1768
1769 def truncate(self, size=None):
1770 """Truncate the file to at most size bytes.
1771
1772 Size defaults to the current file position, as returned by tell().
1773 The current file position is changed to the value of size.
1774 """
1775 self._checkClosed()
1776 self._checkWritable()
1777 if size is None:
1778 size = self.tell()
1779 os.ftruncate(self._fd, size)
1780 self._stat_atopen = None
1781 return size
1782
1783 def close(self):
1784 """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