Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22882

Real Python: Using Python's pathlib Module

$
0
0

Have you struggled with file path handling in Python? With the pathlib module, the struggle is now over! You no longer need to scratch your head over code like this:

>>>
>>> path.rsplit('\\',maxsplit=1)[0]

And you don’t have to cringe at the verbosity of something like this:

>>>
>>> os.path.isfile(os.path.join(os.path.expanduser('~'),'realpython.txt'))

In this video course, you’ll learn how to:

  • Work with file paths in Python
  • Read and write files in new ways
  • Manipulate paths and the underlying file system
  • List files and iterate over them

Using the pathlib module, the two examples above can be rewritten using elegant, readable, and Pythonic code:

>>>
>>> path.parent>>> (pathlib.Path.home()/'realpython.txt').is_file()

That’s what you’ll master in this video course!


[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]


Viewing all articles
Browse latest Browse all 22882

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>