File Methods

MethodDescription
read([size])Read content
readline()Read one line
readlines()Read all lines into a list
write(text)Write a string
writelines(lines)Write multiple lines
seek(offset)Move file cursor
tell()Current cursor position
flush()Flush buffer
close()Close the file
Example
with open("demo.txt", "w", encoding="utf-8") as f:
    f.write("hello")
with open("demo.txt", "r", encoding="utf-8") as f:
    print(f.read())