Python file() Function
Description
file() The function is used to create a file object, which has an alias called open(), more figuratively speaking, they are built-in functions. Parameters are passed as strings.
For more file operations, please refer to:Python File I/O.
Syntax
The syntax of the file() method is as follows:
file(name[, mode[, buffering]])
Parameters
- name -- the file name
- mode -- the opening mode
- buffering -- 0 means no buffering; 1 means line buffering; greater than 1 means the buffer size.
Return Value
A file object.
Example
The test file test.txt has the following contents:
RUNOOB1
RUNOOB2
f
=
file
(
'
test.txt
'
)
f
.
read
(
)
'
RUNOOB1
\n
RUNOOB2
\n
'
Python built-in function