File
A file-like object for reading and writing data.
Created by the open
method of the Operator
class.
closed
property
#
Check if the file is closed.
__enter__()
#
Enter the runtime context related to this object.
__exit__(exc_type, exc_value, traceback)
#
Exit the runtime context related to this object.
close()
#
Close the file.
flush()
#
Flush the internal buffer.
read(size=None)
#
Read the content of the file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
int
|
The number of bytes to read. If None, read all. |
None
|
Returns:
Type | Description |
---|---|
bytes
|
The content of the file as bytes. |
readable()
#
Check if the file is readable.
readinto(buffer)
#
Read bytes into a buffer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
buffer
|
bytes | bytearray
|
The buffer to read into. |
required |
Returns:
Type | Description |
---|---|
int
|
The number of bytes read. |
readline(size=None)
#
Read a single line from the file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
int
|
The number of bytes to read. If None, read until newline. |
None
|
Returns:
Type | Description |
---|---|
bytes
|
The line read from the file as bytes. |
seek(pos, whence=0)
#
Set the file's current position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pos
|
int
|
The position to set. |
required |
whence
|
int
|
The reference point for the position. Can be 0, 1, or 2. |
0
|
Returns:
Type | Description |
---|---|
int
|
The new position in the file. |
seekable()
#
Check if the file supports seeking.
tell()
#
Get the current position in the file.
Returns:
Type | Description |
---|---|
int
|
The current position in the file. |
writable()
#
Check if the file is writable.
write(bs)
#
Write the content to the file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bs
|
bytes
|
The content to write. |
required |