file = open("example.txt", "r") text = file.read() file.close()
with open("example.txt", "w") as file: file.write("Hello, world!")This example shows how to open a file for writing using a TextIOWrapper object and write some text to it using the `write()` method. Package library: io