(self, size=None)
Truncate the file's size.

        If the optional size argument is present, the file is truncated to
        (at most) that size. The size defaults to the current position.
        The current file position is not changed unless the position
        is beyond the new file size.

        If the specified size exceeds the file's current size, the
        file remains unchanged.
Truncate the file's size.
Truncate the file s size .
def truncate(self, size=None):
        """Truncate the file's size.

        If the optional size argument is present, the file is truncated to
        (at most) that size. The size defaults to the current position.
        The current file position is not changed unless the position
        is beyond the new file size.

        If the specified size exceeds the file's current size, the
        file remains unchanged.
        """
        _complain_ifclosed(self.closed)
        if size is None:
            size = self.pos
        elif size < 0:
            raise IOError(22, "Negative size not allowed")
        elif size < self.pos:
            self.pos = size
        self.buf = self.getvalue()[:size]
        self.len = size
def truncate ( self , size = None ) : _complain_ifclosed ( self . closed ) if size is None : size = self . pos elif size < 0 : raise IOError ( 22 , "Negative size not allowed" ) elif size < self . pos : self . pos = size self . buf = self . getvalue ( ) [ : size ] self . len = size