home PYTHONJAVA
 

Python3 file

open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

Parameter Description:

  • file: Required, document way (relative or total path)。
  • mode: Optional, document open mode
  • buffering: Set buffer
  • encoding: 一Set buffer
  • errors: Error level
  • newline: Distinguish line breaks
  • closefd: Incoming document parameter type
  • opener:
The

mode parameter is:

ModeDescription
tText mode (default).
xWrite mode, make another document, and report a blunder if the record as of now exists.
bbinary mode.
+Open a document for refreshing (clear and writable).
UUniversal Wrap Mode (not suggested).
rOpen the document as read-as it were. The pointer to the document will be put toward the start of the record. This is the default mode.
rbOpens a record in twofold organization for read-as it were. The record pointer will be put toward the start of the document. This is the default mode. By and large utilized for non-content documents, for example, pictures.
r+Open a record for perusing and composing. The document pointer will be set toward the start of the record.
rb+Open a document in twofold organization for perusing and composing. The document pointer will be set toward the start of the record. By and large utilized for non-content records, for example, pictures.
wOpen a document for composing as it were. On the off chance that the record as of now exists, open the document and begin altering from the earliest starting point, ie the first substance will be erased. In the event that the record does not exist, make another one.
wbOpen a document in double configuration for composing as it were. On the off chance that the record as of now exists, open the document and begin altering from the earliest starting point, ie the first substance will be erased. On the off chance that the document does not exist, make another one. For the most part utilized for non-content records, for example, pictures.
w+Open a record for perusing and composing. In the event that the document as of now exists, open the record and begin altering from the earliest starting point, ie the first substance will be erased. In the event that the record does not exist, make another one.
wb+Opens a document in twofold organization for perusing and composing. On the off chance that the record as of now exists, open the document and begin altering from the earliest starting point, ie the first substance will be erased. In the event that the document does not exist, make another one. By and large utilized for non-content records, for example, pictures.
aOpen a document for annexing. On the off chance that the record as of now exists, the document pointer will be put toward the finish of the record. As such, the new substance will be kept in touch with the current substance. In the event that the document does not exist, make another record for composing.
abOpens a document in double configuration for attaching. In the event that the record as of now exists, the document pointer will be set toward the finish of the document. At the end of the day, the new substance will be kept in touch with the current substance. On the off chance that the record does not exist, make another document for composing.
a+Open a document for perusing and composing. In the event that the record as of now exists, the document pointer will be put toward the finish of the document. Affix mode will be utilized when the record is opened. On the off chance that the document does not exist, make another record for perusing and composing.
ab+Open a document in double arrangement for affixing. On the off chance that the record as of now exists, the document pointer will be set toward the finish of the document. In the event that the record does not exist, make another document for perusing and composing.

The default is text mode, if you want to open in binary mode, add b .

file object

The file object is created using the open function, and the following table lists the functions commonly used by the file object:

serial numbermethod and description
1

file.close()

Close the file. After the file is closed, the file can no longer be read or written.

2

file.flush()

Refresh the internal buffer of the file, directly write the data of the internal buffer to the file immediately, instead of passively waiting for the output buffer to write.

3

file.fileno()

Returns an integer file descriptor (file descriptor FD integer) that can be used in some underlying operations such as the read method of the os module.

4

file.isatty()

Returns True if the file is connected to an end device, otherwise returns False.

5

file.next()

The File object in Python 3 does not support the next() method.

Return to the next line of the file.

6

file.read([size])

Reads the specified number of bytes from the file and reads all if it is not given or negative.

7

file.readline([size])

Read the entire line, including the "\n" character.

8

file.readlines([sizeint])

Read all rows and return the list. If sizeint>0 is given, return a line with a total of approximately sizeint bytes. The actual read value may be larger than sizeint because the buffer needs to be filled.

9

file.seek(offset[, whence])

Set the current location of the file

10

file.tell()

Returns the current location of the file.

11

file.truncate([size])

Truncate from the first character of the first line of the file, truncating the file to size Characters, no size means truncation from the current position; all characters following the truncation are deleted, and the newline under the Widnows system represents 2 characters.

12

file.write(str)

Write a string to a file, returning the length of the written character.

13

file.writelines(sequence)

Write a list of sequence strings to the file, and if you need to wrap, you must add a newline for each line.






welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.