#3
Inspired Python
Picture of a coiled snake and the main logo of Inspired Python
>>> from pathlib import Path
>>> p = Path('/tmp/inspiredpython.txt')
>>> p.write_text('Hello from Inspired Python')
>>> p.read_text()
'Hello from Inspired Python'

Python Pathlib Tips: Reading from and Writing to Files


You can use the pathlib module’s Path() class to read and write to files directly, circumventing the need for open() if you don’t need access to the file object.

Be Inspired Get Python tips sent to your inbox

We'll tell you about the latest courses and articles.

Absolutely no spam. We promise!