English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
read() This method is used to read a specified number of bytes from the file, or all if not specified or negative.
The syntax of the read() method is as follows:
fileObject.read();
size -- The number of bytes read from the file.
Returns the bytes read from the string.
The following example demonstrates the use of the read() method:
File w3The content of codebox.txt is as follows:
1:fr.oldtoolbag.com 2:fr.oldtoolbag.com 3:fr.oldtoolbag.com 4:fr.oldtoolbag.com 5:fr.oldtoolbag.com
Loop to read the content of the file:
# Open file f = open("w3codebox.txt", "r") print(f.read(20))
The output result of the above example is as follows:
1:fr.oldtoolbag.com 2:ww