ReferenceFile methods
file.read()
Reads the whole file, or a given number of characters.
Signature
f.read(size=-1)Parameters
| Name | Means |
|---|---|
size | how much to read; everything when omitted |
Returns
A string, or bytes in binary mode.
Example
Python
with open("notes.txt", "w", encoding="utf-8") as f:
f.write("Ada,1815\n")
with open("notes.txt", encoding="utf-8") as f:
print(repr(f.read(3)))
print(repr(f.read()))
print(repr(f.read()))Output
'Ada' ',1815\n' ''