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)
| 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. |