Loading video player…

Create Two Directories (Exercise)

Avatar image for kishore.99v

kishore.99v on March 30, 2025

Why I am seeing this error below if I wanted to get the home directory?

>>> import pathlib as Path
>>> Path.home()
Traceback (most recent call last):
  File "<pyshell#14>", line 1, in <module>
    Path.home()
AttributeError: module 'pathlib' has no attribute 'home'
Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on March 31, 2025

@kishore.99v There’s an error in your import statement:

-import pathlib as Path
+from pathlib import Path

When you import the Path class correctly, you’ll be able to call its .home() method:

>>> from pathlib import Path
>>> Path.home()
PosixPath('/home/realpython')

Become a Member to join the conversation.