Python Tutorial Python Advanced Python References Python Libraries

Python - File detach() Method



The Python detach() method is used to separate the underlying raw stream from the buffer and return it. After the raw stream has been detached, the buffer is in an unusable state.

Some buffers, like BytesIO, do not have the concept of a single raw stream to return from this method. They raise UnsupportedOperation.

Syntax

file.detach()

Parameters

No parameter is required.

Return Value

Returns the underlying raw stream separated from the buffer.

Exception

Throws UnsupportedOperation, if the buffer do not have the concept of a single raw stream to return from this method.

❮ Python File Handling Methods