Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python file() Function

Python file() Function

Python built-in function Python built-in 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

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 Python built-in function