Movatterモバイル変換


[0]ホーム

URL:


Loading video player…

Using Python's pathlib Module (Overview)

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

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

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

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

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

  • Work withfile paths in Python
  • Read andwrite files in new ways
  • Manipulate paths and the underlying file system
  • List files anditerate over them

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

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

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

Download

Course Slides (.pdf)

4.2 MB

00:00Using Python’spathlib Module.Have you struggled with file path handling in Python? With thepathlib module,that struggle is over.

00:09You no longer need to scratch your head over code like thisor cringe at the verbosity of code such as this.

00:21Using thepathlib module, these two pieces of code can be rewrittenusing elegant, readable, and Pythonic code, as seen on-screen.

00:35Thepathlib module allows cross-platform, object-oriented file path handling,and in this course, you’ll see how to work with file paths,the names of directories and files; learn new ways to read and write files;manipulate paths and the underlying file system;and see some examples of how to list files that iterate over them.

00:56In this course, you’ll see two different Python REPLs being used,both of which use color-coding,which makes the syntax of examples easier to understand.

01:05For examples that were run on macOS, bpython is being used,while on Windows, the IPython terminal is being used.However,all the code you see running is standard Python and could be run in the PythonREPL, which is typically accessed by typingpython atyour terminal or command prompt.

01:26So now you know what’s going to be covered, let’s get started.

Become a Member to join the conversation.

Course Contents

Overview
16%

[8]ページ先頭

©2009-2026 Movatter.jp