Python file() Function
Description
file()The function is used to create a file object, which has an alias calledopen(), more figuratively, they are built-in functions. Parameters are passed in the form of strings.
For more file operations, refer to:Python File I/O。
Syntax
The following is the syntax of the file() method:
file(name[, mode[, buffering]])
Parameters
- name -- file name
- mode -- open mode
- buffering -- 0 means no buffering, if 1 means line buffering, greater than 1 means buffer size.
Return Value
File object.
Examples
Test file test.txt, content as follows:
EXAMPLE1 EXAMPLE2
>>>f = file('test.txt')
>>> f.read()
'EXAMPLE1\nEXAMPLE2\n'
Python Built-in Functions