with open('myfile.txt') as file: wrapper = TextIOWrapper(file) text = wrapper.read() print(text)
with open('myfile.txt', 'w') as file: wrapper = TextIOWrapper(file) wrapper.write('Hello, world!')In this example, we open a text file named 'myfile.txt' in write mode and create a TextIOWrapper object from the file. We then call the write() method on the TextIOWrapper object to write the string 'Hello, world!' to the file. The TextIOWrapper class is part of the Python IO library, which is included with Python's standard library.