DEV Community

Discussion on: All You Need To Know About Context Managers In Python

Collapse
jerrynsh profile image
Jerry Ng Author

Hey Akin! Good catch!

It was using w only which stands for Write-only. Instead, we should use w+ if we want to allow Read and Write operations.

I've updated it to be:

with open('hello.txt', 'w+') as f:
    data = f.read()
    f.write('Hello Python!')
Enter fullscreen mode Exit fullscreen mode