Linux iad1-shared-b7-18 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
Apache
: 67.205.6.31 | : 216.73.216.47
Cant Read [ /etc/named.conf ]
8.2.29
fernandoquevedo
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
README
+ Create Folder
+ Create File
/
usr /
share /
doc /
python3.10 /
html /
library /
[ HOME SHELL ]
Name
Size
Permission
Action
2to3.html
70.96
KB
-rw-r--r--
__future__.html
20.75
KB
-rw-r--r--
__main__.html
44.87
KB
-rw-r--r--
_thread.html
30.39
KB
-rw-r--r--
abc.html
46.87
KB
-rw-r--r--
aifc.html
35.56
KB
-rw-r--r--
allos.html
34.33
KB
-rw-r--r--
archiving.html
17
KB
-rw-r--r--
argparse.html
300.89
KB
-rw-r--r--
array.html
37.28
KB
-rw-r--r--
ast.html
293.08
KB
-rw-r--r--
asynchat.html
37.41
KB
-rw-r--r--
asyncio-api-index.html
27.68
KB
-rw-r--r--
asyncio-dev.html
36.1
KB
-rw-r--r--
asyncio-eventloop.html
204.43
KB
-rw-r--r--
asyncio-exceptions.html
17.11
KB
-rw-r--r--
asyncio-future.html
38.23
KB
-rw-r--r--
asyncio-llapi-index.html
61.97
KB
-rw-r--r--
asyncio-platforms.html
21.77
KB
-rw-r--r--
asyncio-policy.html
39.56
KB
-rw-r--r--
asyncio-protocol.html
118.33
KB
-rw-r--r--
asyncio-queue.html
31.86
KB
-rw-r--r--
asyncio-stream.html
69.98
KB
-rw-r--r--
asyncio-subprocess.html
49.25
KB
-rw-r--r--
asyncio-sync.html
42.79
KB
-rw-r--r--
asyncio-task.html
109.14
KB
-rw-r--r--
asyncio.html
17.31
KB
-rw-r--r--
asyncore.html
49.36
KB
-rw-r--r--
atexit.html
22.87
KB
-rw-r--r--
audioop.html
46
KB
-rw-r--r--
audit_events.html
72.85
KB
-rw-r--r--
base64.html
48.09
KB
-rw-r--r--
bdb.html
66
KB
-rw-r--r--
binary.html
15.97
KB
-rw-r--r--
binascii.html
36.3
KB
-rw-r--r--
binhex.html
15.97
KB
-rw-r--r--
bisect.html
43.38
KB
-rw-r--r--
builtins.html
14.87
KB
-rw-r--r--
bz2.html
50.68
KB
-rw-r--r--
calendar.html
69.35
KB
-rw-r--r--
cgi.html
59.95
KB
-rw-r--r--
cgitb.html
19.96
KB
-rw-r--r--
chunk.html
22.21
KB
-rw-r--r--
cmath.html
43.89
KB
-rw-r--r--
cmd.html
50.42
KB
-rw-r--r--
code.html
35.38
KB
-rw-r--r--
codecs.html
157.96
KB
-rw-r--r--
codeop.html
18.26
KB
-rw-r--r--
collections.abc.html
79.17
KB
-rw-r--r--
collections.html
189.43
KB
-rw-r--r--
colorsys.html
17.31
KB
-rw-r--r--
compileall.html
50.68
KB
-rw-r--r--
concurrency.html
24.15
KB
-rw-r--r--
concurrent.futures.html
79.03
KB
-rw-r--r--
concurrent.html
11.56
KB
-rw-r--r--
configparser.html
159.4
KB
-rw-r--r--
constants.html
22.41
KB
-rw-r--r--
contextlib.html
117.2
KB
-rw-r--r--
contextvars.html
38.38
KB
-rw-r--r--
copy.html
17.92
KB
-rw-r--r--
copyreg.html
18.63
KB
-rw-r--r--
crypt.html
28.29
KB
-rw-r--r--
crypto.html
13.93
KB
-rw-r--r--
csv.html
82.89
KB
-rw-r--r--
ctypes.html
295.49
KB
-rw-r--r--
curses.ascii.html
32.04
KB
-rw-r--r--
curses.html
221.24
KB
-rw-r--r--
curses.panel.html
22.16
KB
-rw-r--r--
custominterp.html
11.85
KB
-rw-r--r--
dataclasses.html
113.16
KB
-rw-r--r--
datatypes.html
31.82
KB
-rw-r--r--
datetime.html
374.92
KB
-rw-r--r--
dbm.html
51.16
KB
-rw-r--r--
debug.html
17
KB
-rw-r--r--
decimal.html
270.12
KB
-rw-r--r--
development.html
32.34
KB
-rw-r--r--
devmode.html
31.72
KB
-rw-r--r--
dialog.html
43.03
KB
-rw-r--r--
difflib.html
111.99
KB
-rw-r--r--
dis.html
136.07
KB
-rw-r--r--
distribution.html
13.67
KB
-rw-r--r--
distutils.html
14.73
KB
-rw-r--r--
doctest.html
199.32
KB
-rw-r--r--
email.charset.html
31.92
KB
-rw-r--r--
email.compat32-message.html
97.74
KB
-rw-r--r--
email.contentmanager.html
37.02
KB
-rw-r--r--
email.encoders.html
18.47
KB
-rw-r--r--
email.errors.html
24.45
KB
-rw-r--r--
email.examples.html
60.49
KB
-rw-r--r--
email.generator.html
48.79
KB
-rw-r--r--
email.header.html
37.61
KB
-rw-r--r--
email.headerregistry.html
66.26
KB
-rw-r--r--
email.html
30.75
KB
-rw-r--r--
email.iterators.html
18.23
KB
-rw-r--r--
email.message.html
99.75
KB
-rw-r--r--
email.mime.html
44.89
KB
-rw-r--r--
email.parser.html
57.39
KB
-rw-r--r--
email.policy.html
84.24
KB
-rw-r--r--
email.utils.html
42.57
KB
-rw-r--r--
ensurepip.html
23.9
KB
-rw-r--r--
enum.html
151
KB
-rw-r--r--
errno.html
60.17
KB
-rw-r--r--
exceptions.html
108.44
KB
-rw-r--r--
faulthandler.html
31.5
KB
-rw-r--r--
fcntl.html
36.67
KB
-rw-r--r--
filecmp.html
32.08
KB
-rw-r--r--
fileformats.html
13.52
KB
-rw-r--r--
fileinput.html
40.37
KB
-rw-r--r--
filesys.html
16.78
KB
-rw-r--r--
fnmatch.html
21.02
KB
-rw-r--r--
fractions.html
35.29
KB
-rw-r--r--
frameworks.html
16.15
KB
-rw-r--r--
ftplib.html
71.97
KB
-rw-r--r--
functional.html
12.19
KB
-rw-r--r--
functions.html
260.33
KB
-rw-r--r--
functools.html
92.96
KB
-rw-r--r--
gc.html
40.97
KB
-rw-r--r--
getopt.html
29.4
KB
-rw-r--r--
getpass.html
16.01
KB
-rw-r--r--
gettext.html
98.02
KB
-rw-r--r--
glob.html
27.2
KB
-rw-r--r--
graphlib.html
34.82
KB
-rw-r--r--
grp.html
16.03
KB
-rw-r--r--
gzip.html
45.65
KB
-rw-r--r--
hashlib.html
93.19
KB
-rw-r--r--
heapq.html
42.43
KB
-rw-r--r--
hmac.html
24.74
KB
-rw-r--r--
html.entities.html
14.91
KB
-rw-r--r--
html.html
14.81
KB
-rw-r--r--
html.parser.html
47.7
KB
-rw-r--r--
http.client.html
85.63
KB
-rw-r--r--
http.cookiejar.html
113.94
KB
-rw-r--r--
http.cookies.html
47.64
KB
-rw-r--r--
http.html
45.52
KB
-rw-r--r--
http.server.html
73.05
KB
-rw-r--r--
i18n.html
13.44
KB
-rw-r--r--
idle.html
77.18
KB
-rw-r--r--
imaplib.html
87.08
KB
-rw-r--r--
imghdr.html
17.94
KB
-rw-r--r--
imp.html
54.32
KB
-rw-r--r--
importlib.html
239.96
KB
-rw-r--r--
importlib.metadata.html
43.14
KB
-rw-r--r--
index.html
75.06
KB
-rw-r--r--
inspect.html
168.74
KB
-rw-r--r--
internet.html
29.89
KB
-rw-r--r--
intro.html
13.81
KB
-rw-r--r--
io.html
154.15
KB
-rw-r--r--
ipaddress.html
137.75
KB
-rw-r--r--
ipc.html
12.6
KB
-rw-r--r--
itertools.html
153.27
KB
-rw-r--r--
json.html
98.9
KB
-rw-r--r--
keyword.html
14.88
KB
-rw-r--r--
language.html
16.71
KB
-rw-r--r--
linecache.html
18.09
KB
-rw-r--r--
locale.html
77.35
KB
-rw-r--r--
logging.config.html
100.3
KB
-rw-r--r--
logging.handlers.html
146.28
KB
-rw-r--r--
logging.html
169.67
KB
-rw-r--r--
lzma.html
66.89
KB
-rw-r--r--
mailbox.html
176.34
KB
-rw-r--r--
mailcap.html
20.86
KB
-rw-r--r--
markup.html
22.31
KB
-rw-r--r--
marshal.html
24.43
KB
-rw-r--r--
math.html
85.82
KB
-rw-r--r--
mimetypes.html
40.27
KB
-rw-r--r--
mm.html
11.16
KB
-rw-r--r--
mmap.html
55.53
KB
-rw-r--r--
modulefinder.html
23.67
KB
-rw-r--r--
modules.html
15.88
KB
-rw-r--r--
msilib.html
78.38
KB
-rw-r--r--
msvcrt.html
29.22
KB
-rw-r--r--
multiprocessing.html
405.24
KB
-rw-r--r--
multiprocessing.shared_memory....
60
KB
-rw-r--r--
netdata.html
20.24
KB
-rw-r--r--
netrc.html
20.39
KB
-rw-r--r--
nis.html
16.76
KB
-rw-r--r--
nntplib.html
84.93
KB
-rw-r--r--
numbers.html
45.67
KB
-rw-r--r--
numeric.html
19.29
KB
-rw-r--r--
operator.html
107.32
KB
-rw-r--r--
optparse.html
256.96
KB
-rw-r--r--
os.html
594.39
KB
-rw-r--r--
os.path.html
65.54
KB
-rw-r--r--
ossaudiodev.html
56.35
KB
-rw-r--r--
pathlib.html
170.01
KB
-rw-r--r--
pdb.html
68.67
KB
-rw-r--r--
persistence.html
19.13
KB
-rw-r--r--
pickle.html
154.45
KB
-rw-r--r--
pickletools.html
22.92
KB
-rw-r--r--
pipes.html
21.7
KB
-rw-r--r--
pkgutil.html
42.76
KB
-rw-r--r--
platform.html
45.08
KB
-rw-r--r--
plistlib.html
30.06
KB
-rw-r--r--
poplib.html
41.42
KB
-rw-r--r--
posix.html
20.96
KB
-rw-r--r--
pprint.html
55.35
KB
-rw-r--r--
profile.html
84.63
KB
-rw-r--r--
pty.html
23.7
KB
-rw-r--r--
pwd.html
16.84
KB
-rw-r--r--
py_compile.html
29
KB
-rw-r--r--
pyclbr.html
24.06
KB
-rw-r--r--
pydoc.html
19.59
KB
-rw-r--r--
pyexpat.html
104.38
KB
-rw-r--r--
python.html
22.46
KB
-rw-r--r--
queue.html
43.39
KB
-rw-r--r--
quopri.html
18.64
KB
-rw-r--r--
random.html
86.31
KB
-rw-r--r--
re.html
214.24
KB
-rw-r--r--
readline.html
50.19
KB
-rw-r--r--
reprlib.html
30.85
KB
-rw-r--r--
resource.html
48.26
KB
-rw-r--r--
rlcompleter.html
18.06
KB
-rw-r--r--
runpy.html
30.99
KB
-rw-r--r--
sched.html
27.04
KB
-rw-r--r--
secrets.html
30.2
KB
-rw-r--r--
security_warnings.html
16.21
KB
-rw-r--r--
select.html
74.58
KB
-rw-r--r--
selectors.html
41.91
KB
-rw-r--r--
shelve.html
36.54
KB
-rw-r--r--
shlex.html
61.03
KB
-rw-r--r--
shutil.html
100.13
KB
-rw-r--r--
signal.html
95.39
KB
-rw-r--r--
site.html
38.16
KB
-rw-r--r--
smtpd.html
44.09
KB
-rw-r--r--
smtplib.html
81.4
KB
-rw-r--r--
sndhdr.html
16.4
KB
-rw-r--r--
socket.html
256.95
KB
-rw-r--r--
socketserver.html
91.95
KB
-rw-r--r--
spwd.html
16.71
KB
-rw-r--r--
sqlite3.html
225.51
KB
-rw-r--r--
ssl.html
328.83
KB
-rw-r--r--
stat.html
57.79
KB
-rw-r--r--
statistics.html
123.22
KB
-rw-r--r--
stdtypes.html
615.43
KB
-rw-r--r--
string.html
108.03
KB
-rw-r--r--
stringprep.html
24.94
KB
-rw-r--r--
struct.html
70.58
KB
-rw-r--r--
subprocess.html
199.03
KB
-rw-r--r--
sunau.html
39.84
KB
-rw-r--r--
superseded.html
26.21
KB
-rw-r--r--
symtable.html
33.26
KB
-rw-r--r--
sys.html
198.83
KB
-rw-r--r--
sysconfig.html
39.81
KB
-rw-r--r--
syslog.html
27.36
KB
-rw-r--r--
tabnanny.html
16.18
KB
-rw-r--r--
tarfile.html
161.92
KB
-rw-r--r--
telnetlib.html
38.21
KB
-rw-r--r--
tempfile.html
58.39
KB
-rw-r--r--
termios.html
22.86
KB
-rw-r--r--
test.html
222.85
KB
-rw-r--r--
text.html
16.8
KB
-rw-r--r--
textwrap.html
48.83
KB
-rw-r--r--
threading.html
128.33
KB
-rw-r--r--
time.html
107.46
KB
-rw-r--r--
timeit.html
52.63
KB
-rw-r--r--
tk.html
28.08
KB
-rw-r--r--
tkinter.colorchooser.html
14.49
KB
-rw-r--r--
tkinter.dnd.html
17.09
KB
-rw-r--r--
tkinter.font.html
22.21
KB
-rw-r--r--
tkinter.html
106.85
KB
-rw-r--r--
tkinter.messagebox.html
20.09
KB
-rw-r--r--
tkinter.scrolledtext.html
14.52
KB
-rw-r--r--
tkinter.tix.html
59.69
KB
-rw-r--r--
tkinter.ttk.html
138.37
KB
-rw-r--r--
token.html
45.73
KB
-rw-r--r--
tokenize.html
39.86
KB
-rw-r--r--
trace.html
38.85
KB
-rw-r--r--
traceback.html
75.61
KB
-rw-r--r--
tracemalloc.html
122.33
KB
-rw-r--r--
tty.html
14.46
KB
-rw-r--r--
turtle.html
271.71
KB
-rw-r--r--
types.html
64.85
KB
-rw-r--r--
typing.html
315.69
KB
-rw-r--r--
unicodedata.html
27.3
KB
-rw-r--r--
unittest.html
310.01
KB
-rw-r--r--
unittest.mock-examples.html
177.75
KB
-rw-r--r--
unittest.mock.html
363.51
KB
-rw-r--r--
unix.html
13.46
KB
-rw-r--r--
urllib.error.html
18.56
KB
-rw-r--r--
urllib.html
12.92
KB
-rw-r--r--
urllib.parse.html
104.65
KB
-rw-r--r--
urllib.request.html
208.87
KB
-rw-r--r--
urllib.robotparser.html
22.63
KB
-rw-r--r--
uu.html
18.2
KB
-rw-r--r--
uuid.html
42.88
KB
-rw-r--r--
venv.html
90.43
KB
-rw-r--r--
warnings.html
69.13
KB
-rw-r--r--
wave.html
36.12
KB
-rw-r--r--
weakref.html
73.36
KB
-rw-r--r--
webbrowser.html
33.98
KB
-rw-r--r--
windows.html
12.32
KB
-rw-r--r--
winreg.html
89.48
KB
-rw-r--r--
winsound.html
26.3
KB
-rw-r--r--
wsgiref.html
111.52
KB
-rw-r--r--
xdrlib.html
42.07
KB
-rw-r--r--
xml.dom.html
114.66
KB
-rw-r--r--
xml.dom.minidom.html
49.6
KB
-rw-r--r--
xml.dom.pulldom.html
30.06
KB
-rw-r--r--
xml.etree.elementtree.html
186.49
KB
-rw-r--r--
xml.html
22.34
KB
-rw-r--r--
xml.sax.handler.html
55.78
KB
-rw-r--r--
xml.sax.html
31.74
KB
-rw-r--r--
xml.sax.reader.html
56.23
KB
-rw-r--r--
xml.sax.utils.html
22.28
KB
-rw-r--r--
xmlrpc.client.html
79.73
KB
-rw-r--r--
xmlrpc.html
11.9
KB
-rw-r--r--
xmlrpc.server.html
63.56
KB
-rw-r--r--
zipapp.html
52.45
KB
-rw-r--r--
zipfile.html
116.59
KB
-rw-r--r--
zipimport.html
33.76
KB
-rw-r--r--
zlib.html
42.29
KB
-rw-r--r--
zoneinfo.html
57.25
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : pathlib.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> <title>pathlib — Object-oriented filesystem paths — Python 3.10.12 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="../_static/pygments.css" /> <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?2022.1" /> <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script> <script src="../_static/jquery.js"></script> <script src="../_static/underscore.js"></script> <script src="../_static/doctools.js"></script> <script src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 3.10.12 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="next" title="os.path — Common pathname manipulations" href="os.path.html" /> <link rel="prev" title="File and Directory Access" href="filesys.html" /> <link rel="canonical" href="file:///usr/share/doc/python3.10/html/library/pathlib.html" /> <style> @media only screen { table.full-width-table { width: 100%; } } </style> <link rel="shortcut icon" type="image/png" href="../_static/py.svg" /> <script type="text/javascript" src="../_static/copybutton.js"></script> <script type="text/javascript" src="../_static/menu.js"></script> </head> <body> <div class="mobile-nav"> <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation" aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" /> <label for="menuToggler" class="toggler__label"> <span></span> </label> <nav class="nav-content" role="navigation"> <a href="https://www.python.org/" class="nav-logo"> <img src="../_static/py.svg" alt="Logo"/> </a> <div class="version_switcher_placeholder"></div> <form role="search" class="search" action="../search.html" method="get"> <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon"> <path fill-rule="nonzero" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" fill="#444"></path> </svg> <input type="text" name="q" aria-label="Quick search"/> <input type="submit" value="Go"/> </form> </nav> <div class="menu-wrapper"> <nav class="menu" role="navigation" aria-label="main navigation"> <div class="language_switcher_placeholder"></div> <h3><a href="../contents.html">Table of Contents</a></h3> <ul> <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code> — Object-oriented filesystem paths</a><ul> <li><a class="reference internal" href="#basic-use">Basic use</a></li> <li><a class="reference internal" href="#pure-paths">Pure paths</a><ul> <li><a class="reference internal" href="#general-properties">General properties</a></li> <li><a class="reference internal" href="#operators">Operators</a></li> <li><a class="reference internal" href="#accessing-individual-parts">Accessing individual parts</a></li> <li><a class="reference internal" href="#methods-and-properties">Methods and properties</a></li> </ul> </li> <li><a class="reference internal" href="#concrete-paths">Concrete paths</a><ul> <li><a class="reference internal" href="#methods">Methods</a></li> </ul> </li> <li><a class="reference internal" href="#correspondence-to-tools-in-the-os-module">Correspondence to tools in the <code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code> module</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="filesys.html" title="previous chapter">File and Directory Access</a></p> <h4>Next topic</h4> <p class="topless"><a href="os.path.html" title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code> — Common pathname manipulations</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li> <a href="https://github.com/python/cpython/blob/3.10/Doc/library/pathlib.rst" rel="nofollow">Show Source </a> </li> </ul> </div> </nav> </div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="os.path.html" title="os.path — Common pathname manipulations" accesskey="N">next</a> |</li> <li class="right" > <a href="filesys.html" title="File and Directory Access" accesskey="P">previous</a> |</li> <li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li class="switchers"> <div class="language_switcher_placeholder"></div> <div class="version_switcher_placeholder"></div> </li> <li> </li> <li id="cpython-language-and-version"> <a href="../index.html">3.10.12 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="filesys.html" accesskey="U">File and Directory Access</a> »</li> <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code> — Object-oriented filesystem paths</a></li> <li class="right"> <div class="inline-search" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" aria-label="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> | </li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <section id="module-pathlib"> <span id="pathlib-object-oriented-filesystem-paths"></span><h1><a class="reference internal" href="#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a> — Object-oriented filesystem paths<a class="headerlink" href="#module-pathlib" title="Permalink to this headline">¶</a></h1> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.10/Lib/pathlib.py">Lib/pathlib.py</a></p> <hr class="docutils" id="index-0" /> <p>This module offers classes representing filesystem paths with semantics appropriate for different operating systems. Path classes are divided between <a class="reference internal" href="#pure-paths"><span class="std std-ref">pure paths</span></a>, which provide purely computational operations without I/O, and <a class="reference internal" href="#concrete-paths"><span class="std std-ref">concrete paths</span></a>, which inherit from pure paths but also provide I/O operations.</p> <img alt="../_images/pathlib-inheritance.png" class="align-center" src="../_images/pathlib-inheritance.png" /> <p>If you’ve never used this module before or just aren’t sure which class is right for your task, <a class="reference internal" href="#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">Path</span></code></a> is most likely what you need. It instantiates a <a class="reference internal" href="#concrete-paths"><span class="std std-ref">concrete path</span></a> for the platform the code is running on.</p> <p>Pure paths are useful in some special cases; for example:</p> <ol class="arabic simple"> <li><p>If you want to manipulate Windows paths on a Unix machine (or vice versa). You cannot instantiate a <a class="reference internal" href="#pathlib.WindowsPath" title="pathlib.WindowsPath"><code class="xref py py-class docutils literal notranslate"><span class="pre">WindowsPath</span></code></a> when running on Unix, but you can instantiate <a class="reference internal" href="#pathlib.PureWindowsPath" title="pathlib.PureWindowsPath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PureWindowsPath</span></code></a>.</p></li> <li><p>You want to make sure that your code only manipulates paths without actually accessing the OS. In this case, instantiating one of the pure classes may be useful since those simply don’t have any OS-accessing operations.</p></li> </ol> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p><span class="target" id="index-1"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0428"><strong>PEP 428</strong></a>: The pathlib module – object-oriented filesystem paths.</p> </div> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p>For low-level path manipulation on strings, you can also use the <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a> module.</p> </div> <section id="basic-use"> <h2>Basic use<a class="headerlink" href="#basic-use" title="Permalink to this headline">¶</a></h2> <p>Importing the main class:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span> </pre></div> </div> <p>Listing subdirectories:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'.'</span><span class="p">)</span> <span class="gp">>>> </span><span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">iterdir</span><span class="p">()</span> <span class="k">if</span> <span class="n">x</span><span class="o">.</span><span class="n">is_dir</span><span class="p">()]</span> <span class="go">[PosixPath('.hg'), PosixPath('docs'), PosixPath('dist'),</span> <span class="go"> PosixPath('__pycache__'), PosixPath('build')]</span> </pre></div> </div> <p>Listing Python source files in this directory tree:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">list</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="s1">'**/*.py'</span><span class="p">))</span> <span class="go">[PosixPath('test_pathlib.py'), PosixPath('setup.py'),</span> <span class="go"> PosixPath('pathlib.py'), PosixPath('docs/conf.py'),</span> <span class="go"> PosixPath('build/lib/pathlib.py')]</span> </pre></div> </div> <p>Navigating inside a directory tree:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">q</span> <span class="o">=</span> <span class="n">p</span> <span class="o">/</span> <span class="s1">'init.d'</span> <span class="o">/</span> <span class="s1">'reboot'</span> <span class="gp">>>> </span><span class="n">q</span> <span class="go">PosixPath('/etc/init.d/reboot')</span> <span class="gp">>>> </span><span class="n">q</span><span class="o">.</span><span class="n">resolve</span><span class="p">()</span> <span class="go">PosixPath('/etc/rc.d/init.d/halt')</span> </pre></div> </div> <p>Querying path properties:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">q</span><span class="o">.</span><span class="n">exists</span><span class="p">()</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">q</span><span class="o">.</span><span class="n">is_dir</span><span class="p">()</span> <span class="go">False</span> </pre></div> </div> <p>Opening a file:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">with</span> <span class="n">q</span><span class="o">.</span><span class="n">open</span><span class="p">()</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span> <span class="gp">...</span> <span class="go">'#!/bin/bash\n'</span> </pre></div> </div> </section> <section id="pure-paths"> <span id="id1"></span><h2>Pure paths<a class="headerlink" href="#pure-paths" title="Permalink to this headline">¶</a></h2> <p>Pure path objects provide path-handling operations which don’t actually access a filesystem. There are three ways to access these classes, which we also call <em>flavours</em>:</p> <dl class="py class"> <dt class="sig sig-object py" id="pathlib.PurePath"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pathlib.</span></span><span class="sig-name descname"><span class="pre">PurePath</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">pathsegments</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PurePath" title="Permalink to this definition">¶</a></dt> <dd><p>A generic class that represents the system’s path flavour (instantiating it creates either a <a class="reference internal" href="#pathlib.PurePosixPath" title="pathlib.PurePosixPath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePosixPath</span></code></a> or a <a class="reference internal" href="#pathlib.PureWindowsPath" title="pathlib.PureWindowsPath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PureWindowsPath</span></code></a>):</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePath</span><span class="p">(</span><span class="s1">'setup.py'</span><span class="p">)</span> <span class="c1"># Running on a Unix machine</span> <span class="go">PurePosixPath('setup.py')</span> </pre></div> </div> <p>Each element of <em>pathsegments</em> can be either a string representing a path segment, an object implementing the <a class="reference internal" href="os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a> interface which returns a string, or another path object:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePath</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span> <span class="s1">'some/path'</span><span class="p">,</span> <span class="s1">'bar'</span><span class="p">)</span> <span class="go">PurePosixPath('foo/some/path/bar')</span> <span class="gp">>>> </span><span class="n">PurePath</span><span class="p">(</span><span class="n">Path</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">),</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'bar'</span><span class="p">))</span> <span class="go">PurePosixPath('foo/bar')</span> </pre></div> </div> <p>When <em>pathsegments</em> is empty, the current directory is assumed:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePath</span><span class="p">()</span> <span class="go">PurePosixPath('.')</span> </pre></div> </div> <p>If a segment is an absolute path, all previous segments are ignored (like <a class="reference internal" href="os.path.html#os.path.join" title="os.path.join"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.join()</span></code></a>):</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePath</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">,</span> <span class="s1">'/usr'</span><span class="p">,</span> <span class="s1">'lib64'</span><span class="p">)</span> <span class="go">PurePosixPath('/usr/lib64')</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/Windows'</span><span class="p">,</span> <span class="s1">'d:bar'</span><span class="p">)</span> <span class="go">PureWindowsPath('d:bar')</span> </pre></div> </div> <p>On Windows, the drive is not reset when a rooted relative path segment (e.g., <code class="docutils literal notranslate"><span class="pre">r'\foo'</span></code>) is encountered:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/Windows'</span><span class="p">,</span> <span class="s1">'/Program Files'</span><span class="p">)</span> <span class="go">PureWindowsPath('c:/Program Files')</span> </pre></div> </div> <p>Spurious slashes and single dots are collapsed, but double dots (<code class="docutils literal notranslate"><span class="pre">'..'</span></code>) and leading double slashes (<code class="docutils literal notranslate"><span class="pre">'//'</span></code>) are not, since this would change the meaning of a path for various reasons (e.g. symbolic links, UNC paths):</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePath</span><span class="p">(</span><span class="s1">'foo//bar'</span><span class="p">)</span> <span class="go">PurePosixPath('foo/bar')</span> <span class="gp">>>> </span><span class="n">PurePath</span><span class="p">(</span><span class="s1">'//foo/bar'</span><span class="p">)</span> <span class="go">PurePosixPath('//foo/bar')</span> <span class="gp">>>> </span><span class="n">PurePath</span><span class="p">(</span><span class="s1">'foo/./bar'</span><span class="p">)</span> <span class="go">PurePosixPath('foo/bar')</span> <span class="gp">>>> </span><span class="n">PurePath</span><span class="p">(</span><span class="s1">'foo/../bar'</span><span class="p">)</span> <span class="go">PurePosixPath('foo/../bar')</span> </pre></div> </div> <p>(a naïve approach would make <code class="docutils literal notranslate"><span class="pre">PurePosixPath('foo/../bar')</span></code> equivalent to <code class="docutils literal notranslate"><span class="pre">PurePosixPath('bar')</span></code>, which is wrong if <code class="docutils literal notranslate"><span class="pre">foo</span></code> is a symbolic link to another directory)</p> <p>Pure path objects implement the <a class="reference internal" href="os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a> interface, allowing them to be used anywhere the interface is accepted.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.6: </span>Added support for the <a class="reference internal" href="os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a> interface.</p> </div> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="pathlib.PurePosixPath"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pathlib.</span></span><span class="sig-name descname"><span class="pre">PurePosixPath</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">pathsegments</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PurePosixPath" title="Permalink to this definition">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePath</span></code></a>, this path flavour represents non-Windows filesystem paths:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span> <span class="go">PurePosixPath('/etc')</span> </pre></div> </div> <p><em>pathsegments</em> is specified similarly to <a class="reference internal" href="#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePath</span></code></a>.</p> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="pathlib.PureWindowsPath"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pathlib.</span></span><span class="sig-name descname"><span class="pre">PureWindowsPath</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">pathsegments</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PureWindowsPath" title="Permalink to this definition">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePath</span></code></a>, this path flavour represents Windows filesystem paths, including <a class="reference external" href="https://en.wikipedia.org/wiki/Path_(computing)#UNC">UNC paths</a>:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/Program Files/'</span><span class="p">)</span> <span class="go">PureWindowsPath('c:/Program Files')</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'//server/share/file'</span><span class="p">)</span> <span class="go">PureWindowsPath('//server/share/file')</span> </pre></div> </div> <p><em>pathsegments</em> is specified similarly to <a class="reference internal" href="#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePath</span></code></a>.</p> </dd></dl> <p>Regardless of the system you’re running on, you can instantiate all of these classes, since they don’t provide any operation that does system calls.</p> <section id="general-properties"> <h3>General properties<a class="headerlink" href="#general-properties" title="Permalink to this headline">¶</a></h3> <p>Paths are immutable and <a class="reference internal" href="../glossary.html#term-hashable"><span class="xref std std-term">hashable</span></a>. Paths of a same flavour are comparable and orderable. These properties respect the flavour’s case-folding semantics:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span> <span class="o">==</span> <span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'FOO'</span><span class="p">)</span> <span class="go">False</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span> <span class="o">==</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'FOO'</span><span class="p">)</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'FOO'</span><span class="p">)</span> <span class="ow">in</span> <span class="p">{</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span> <span class="p">}</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'C:'</span><span class="p">)</span> <span class="o"><</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'d:'</span><span class="p">)</span> <span class="go">True</span> </pre></div> </div> <p>Paths of a different flavour compare unequal and cannot be ordered:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span> <span class="o">==</span> <span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span> <span class="go">False</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span> <span class="o"><</span> <span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span> <span class="gt">Traceback (most recent call last):</span> File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span> <span class="gr">TypeError</span>: <span class="n">'<' not supported between instances of 'PureWindowsPath' and 'PurePosixPath'</span> </pre></div> </div> </section> <section id="operators"> <h3>Operators<a class="headerlink" href="#operators" title="Permalink to this headline">¶</a></h3> <p>The slash operator helps create child paths, like <a class="reference internal" href="os.path.html#os.path.join" title="os.path.join"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.join()</span></code></a>. If the argument is an absolute path, the previous path is ignored. On Windows, the drive is not reset when the argument is a rooted relative path (e.g., <code class="docutils literal notranslate"><span class="pre">r'\foo'</span></code>):</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PurePath</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span> <span class="go">PurePosixPath('/etc')</span> <span class="gp">>>> </span><span class="n">p</span> <span class="o">/</span> <span class="s1">'init.d'</span> <span class="o">/</span> <span class="s1">'apache2'</span> <span class="go">PurePosixPath('/etc/init.d/apache2')</span> <span class="gp">>>> </span><span class="n">q</span> <span class="o">=</span> <span class="n">PurePath</span><span class="p">(</span><span class="s1">'bin'</span><span class="p">)</span> <span class="gp">>>> </span><span class="s1">'/usr'</span> <span class="o">/</span> <span class="n">q</span> <span class="go">PurePosixPath('/usr/bin')</span> <span class="gp">>>> </span><span class="n">p</span> <span class="o">/</span> <span class="s1">'/an_absolute_path'</span> <span class="go">PurePosixPath('/an_absolute_path')</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/Windows'</span><span class="p">,</span> <span class="s1">'/Program Files'</span><span class="p">)</span> <span class="go">PureWindowsPath('c:/Program Files')</span> </pre></div> </div> <p>A path object can be used anywhere an object implementing <a class="reference internal" href="os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a> is accepted:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">os</span> <span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PurePath</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">os</span><span class="o">.</span><span class="n">fspath</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="go">'/etc'</span> </pre></div> </div> <p>The string representation of a path is the raw filesystem path itself (in native form, e.g. with backslashes under Windows), which you can pass to any function taking a file path as a string:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PurePath</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="go">'/etc'</span> <span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/Program Files'</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="go">'c:\\Program Files'</span> </pre></div> </div> <p>Similarly, calling <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> on a path gives the raw filesystem path as a bytes object, as encoded by <a class="reference internal" href="os.html#os.fsencode" title="os.fsencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsencode()</span></code></a>:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">bytes</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="go">b'/etc'</span> </pre></div> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <p>Calling <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> is only recommended under Unix. Under Windows, the unicode form is the canonical representation of filesystem paths.</p> </div> </section> <section id="accessing-individual-parts"> <h3>Accessing individual parts<a class="headerlink" href="#accessing-individual-parts" title="Permalink to this headline">¶</a></h3> <p>To access the individual “parts” (components) of a path, use the following property:</p> <dl class="py attribute"> <dt class="sig sig-object py" id="pathlib.PurePath.parts"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">parts</span></span><a class="headerlink" href="#pathlib.PurePath.parts" title="Permalink to this definition">¶</a></dt> <dd><p>A tuple giving access to the path’s various components:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PurePath</span><span class="p">(</span><span class="s1">'/usr/bin/python3'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">parts</span> <span class="go">('/', 'usr', 'bin', 'python3')</span> <span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/Program Files/PSF'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">parts</span> <span class="go">('c:\\', 'Program Files', 'PSF')</span> </pre></div> </div> <p>(note how the drive and local root are regrouped in a single part)</p> </dd></dl> </section> <section id="methods-and-properties"> <h3>Methods and properties<a class="headerlink" href="#methods-and-properties" title="Permalink to this headline">¶</a></h3> <p>Pure paths provide the following methods and properties:</p> <dl class="py attribute"> <dt class="sig sig-object py" id="pathlib.PurePath.drive"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">drive</span></span><a class="headerlink" href="#pathlib.PurePath.drive" title="Permalink to this definition">¶</a></dt> <dd><p>A string representing the drive letter or name, if any:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/Program Files/'</span><span class="p">)</span><span class="o">.</span><span class="n">drive</span> <span class="go">'c:'</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'/Program Files/'</span><span class="p">)</span><span class="o">.</span><span class="n">drive</span> <span class="go">''</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span><span class="o">.</span><span class="n">drive</span> <span class="go">''</span> </pre></div> </div> <p>UNC shares are also considered drives:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'//host/share/foo.txt'</span><span class="p">)</span><span class="o">.</span><span class="n">drive</span> <span class="go">'\\\\host\\share'</span> </pre></div> </div> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="pathlib.PurePath.root"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">root</span></span><a class="headerlink" href="#pathlib.PurePath.root" title="Permalink to this definition">¶</a></dt> <dd><p>A string representing the (local or global) root, if any:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/Program Files/'</span><span class="p">)</span><span class="o">.</span><span class="n">root</span> <span class="go">'\\'</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:Program Files/'</span><span class="p">)</span><span class="o">.</span><span class="n">root</span> <span class="go">''</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span><span class="o">.</span><span class="n">root</span> <span class="go">'/'</span> </pre></div> </div> <p>UNC shares always have a root:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'//host/share'</span><span class="p">)</span><span class="o">.</span><span class="n">root</span> <span class="go">'\\'</span> </pre></div> </div> <p>If the path starts with more than two successive slashes, <a class="reference internal" href="#pathlib.PurePosixPath" title="pathlib.PurePosixPath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePosixPath</span></code></a> collapses them:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'//etc'</span><span class="p">)</span><span class="o">.</span><span class="n">root</span> <span class="go">'//'</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'///etc'</span><span class="p">)</span><span class="o">.</span><span class="n">root</span> <span class="go">'/'</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'////etc'</span><span class="p">)</span><span class="o">.</span><span class="n">root</span> <span class="go">'/'</span> </pre></div> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <p>This behavior conforms to <em>The Open Group Base Specifications Issue 6</em>, paragraph <a class="reference external" href="https://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11">4.11 Pathname Resolution</a>:</p> <p><em>“A pathname that begins with two successive slashes may be interpreted in an implementation-defined manner, although more than two leading slashes shall be treated as a single slash.”</em></p> </div> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="pathlib.PurePath.anchor"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">anchor</span></span><a class="headerlink" href="#pathlib.PurePath.anchor" title="Permalink to this definition">¶</a></dt> <dd><p>The concatenation of the drive and root:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/Program Files/'</span><span class="p">)</span><span class="o">.</span><span class="n">anchor</span> <span class="go">'c:\\'</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:Program Files/'</span><span class="p">)</span><span class="o">.</span><span class="n">anchor</span> <span class="go">'c:'</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span><span class="o">.</span><span class="n">anchor</span> <span class="go">'/'</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'//host/share'</span><span class="p">)</span><span class="o">.</span><span class="n">anchor</span> <span class="go">'\\\\host\\share\\'</span> </pre></div> </div> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="pathlib.PurePath.parents"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">parents</span></span><a class="headerlink" href="#pathlib.PurePath.parents" title="Permalink to this definition">¶</a></dt> <dd><p>An immutable sequence providing access to the logical ancestors of the path:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/foo/bar/setup.py'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">parents</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="go">PureWindowsPath('c:/foo/bar')</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">parents</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="go">PureWindowsPath('c:/foo')</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">parents</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="go">PureWindowsPath('c:/')</span> </pre></div> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.10: </span>The parents sequence now supports <a class="reference internal" href="../glossary.html#term-slice"><span class="xref std std-term">slices</span></a> and negative index values.</p> </div> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="pathlib.PurePath.parent"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">parent</span></span><a class="headerlink" href="#pathlib.PurePath.parent" title="Permalink to this definition">¶</a></dt> <dd><p>The logical parent of the path:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'/a/b/c/d'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">parent</span> <span class="go">PurePosixPath('/a/b/c')</span> </pre></div> </div> <p>You cannot go past an anchor, or empty path:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'/'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">parent</span> <span class="go">PurePosixPath('/')</span> <span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'.'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">parent</span> <span class="go">PurePosixPath('.')</span> </pre></div> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <p>This is a purely lexical operation, hence the following behaviour:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'foo/..'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">parent</span> <span class="go">PurePosixPath('foo')</span> </pre></div> </div> <p>If you want to walk an arbitrary filesystem path upwards, it is recommended to first call <a class="reference internal" href="#pathlib.Path.resolve" title="pathlib.Path.resolve"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.resolve()</span></code></a> so as to resolve symlinks and eliminate <cite>“..”</cite> components.</p> </div> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="pathlib.PurePath.name"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#pathlib.PurePath.name" title="Permalink to this definition">¶</a></dt> <dd><p>A string representing the final path component, excluding the drive and root, if any:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'my/library/setup.py'</span><span class="p">)</span><span class="o">.</span><span class="n">name</span> <span class="go">'setup.py'</span> </pre></div> </div> <p>UNC drive names are not considered:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'//some/share/setup.py'</span><span class="p">)</span><span class="o">.</span><span class="n">name</span> <span class="go">'setup.py'</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'//some/share'</span><span class="p">)</span><span class="o">.</span><span class="n">name</span> <span class="go">''</span> </pre></div> </div> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="pathlib.PurePath.suffix"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">suffix</span></span><a class="headerlink" href="#pathlib.PurePath.suffix" title="Permalink to this definition">¶</a></dt> <dd><p>The file extension of the final component, if any:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'my/library/setup.py'</span><span class="p">)</span><span class="o">.</span><span class="n">suffix</span> <span class="go">'.py'</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'my/library.tar.gz'</span><span class="p">)</span><span class="o">.</span><span class="n">suffix</span> <span class="go">'.gz'</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'my/library'</span><span class="p">)</span><span class="o">.</span><span class="n">suffix</span> <span class="go">''</span> </pre></div> </div> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="pathlib.PurePath.suffixes"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">suffixes</span></span><a class="headerlink" href="#pathlib.PurePath.suffixes" title="Permalink to this definition">¶</a></dt> <dd><p>A list of the path’s file extensions:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'my/library.tar.gar'</span><span class="p">)</span><span class="o">.</span><span class="n">suffixes</span> <span class="go">['.tar', '.gar']</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'my/library.tar.gz'</span><span class="p">)</span><span class="o">.</span><span class="n">suffixes</span> <span class="go">['.tar', '.gz']</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'my/library'</span><span class="p">)</span><span class="o">.</span><span class="n">suffixes</span> <span class="go">[]</span> </pre></div> </div> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="pathlib.PurePath.stem"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">stem</span></span><a class="headerlink" href="#pathlib.PurePath.stem" title="Permalink to this definition">¶</a></dt> <dd><p>The final path component, without its suffix:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'my/library.tar.gz'</span><span class="p">)</span><span class="o">.</span><span class="n">stem</span> <span class="go">'library.tar'</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'my/library.tar'</span><span class="p">)</span><span class="o">.</span><span class="n">stem</span> <span class="go">'library'</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'my/library'</span><span class="p">)</span><span class="o">.</span><span class="n">stem</span> <span class="go">'library'</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.PurePath.as_posix"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">as_posix</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PurePath.as_posix" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string representation of the path with forward slashes (<code class="docutils literal notranslate"><span class="pre">/</span></code>):</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:</span><span class="se">\\</span><span class="s1">windows'</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="go">'c:\\windows'</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">as_posix</span><span class="p">()</span> <span class="go">'c:/windows'</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.PurePath.as_uri"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">as_uri</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PurePath.as_uri" title="Permalink to this definition">¶</a></dt> <dd><p>Represent the path as a <code class="docutils literal notranslate"><span class="pre">file</span></code> URI. <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is raised if the path isn’t absolute.</p> <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'/etc/passwd'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">as_uri</span><span class="p">()</span> <span class="go">'file:///etc/passwd'</span> <span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/Windows'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">as_uri</span><span class="p">()</span> <span class="go">'file:///c:/Windows'</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.PurePath.is_absolute"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">is_absolute</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PurePath.is_absolute" title="Permalink to this definition">¶</a></dt> <dd><p>Return whether the path is absolute or not. A path is considered absolute if it has both a root and (if the flavour allows) a drive:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'/a/b'</span><span class="p">)</span><span class="o">.</span><span class="n">is_absolute</span><span class="p">()</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'a/b'</span><span class="p">)</span><span class="o">.</span><span class="n">is_absolute</span><span class="p">()</span> <span class="go">False</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/a/b'</span><span class="p">)</span><span class="o">.</span><span class="n">is_absolute</span><span class="p">()</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'/a/b'</span><span class="p">)</span><span class="o">.</span><span class="n">is_absolute</span><span class="p">()</span> <span class="go">False</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:'</span><span class="p">)</span><span class="o">.</span><span class="n">is_absolute</span><span class="p">()</span> <span class="go">False</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'//some/share'</span><span class="p">)</span><span class="o">.</span><span class="n">is_absolute</span><span class="p">()</span> <span class="go">True</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.PurePath.is_relative_to"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">is_relative_to</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PurePath.is_relative_to" title="Permalink to this definition">¶</a></dt> <dd><p>Return whether or not this path is relative to the <em>other</em> path.</p> <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PurePath</span><span class="p">(</span><span class="s1">'/etc/passwd'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">is_relative_to</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">is_relative_to</span><span class="p">(</span><span class="s1">'/usr'</span><span class="p">)</span> <span class="go">False</span> </pre></div> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.9.</span></p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.PurePath.is_reserved"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">is_reserved</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PurePath.is_reserved" title="Permalink to this definition">¶</a></dt> <dd><p>With <a class="reference internal" href="#pathlib.PureWindowsPath" title="pathlib.PureWindowsPath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PureWindowsPath</span></code></a>, return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the path is considered reserved under Windows, <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise. With <a class="reference internal" href="#pathlib.PurePosixPath" title="pathlib.PurePosixPath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePosixPath</span></code></a>, <code class="docutils literal notranslate"><span class="pre">False</span></code> is always returned.</p> <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'nul'</span><span class="p">)</span><span class="o">.</span><span class="n">is_reserved</span><span class="p">()</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'nul'</span><span class="p">)</span><span class="o">.</span><span class="n">is_reserved</span><span class="p">()</span> <span class="go">False</span> </pre></div> </div> <p>File system calls on reserved paths can fail mysteriously or have unintended effects.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.PurePath.joinpath"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">joinpath</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PurePath.joinpath" title="Permalink to this definition">¶</a></dt> <dd><p>Calling this method is equivalent to combining the path with each of the <em>other</em> arguments in turn:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'passwd'</span><span class="p">)</span> <span class="go">PurePosixPath('/etc/passwd')</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'passwd'</span><span class="p">))</span> <span class="go">PurePosixPath('/etc/passwd')</span> <span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'init.d'</span><span class="p">,</span> <span class="s1">'apache2'</span><span class="p">)</span> <span class="go">PurePosixPath('/etc/init.d/apache2')</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:'</span><span class="p">)</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">'/Program Files'</span><span class="p">)</span> <span class="go">PureWindowsPath('c:/Program Files')</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.PurePath.match"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">match</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pattern</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PurePath.match" title="Permalink to this definition">¶</a></dt> <dd><p>Match this path against the provided glob-style pattern. Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if matching is successful, <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.</p> <p>If <em>pattern</em> is relative, the path can be either relative or absolute, and matching is done from the right:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePath</span><span class="p">(</span><span class="s1">'a/b.py'</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">'*.py'</span><span class="p">)</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">PurePath</span><span class="p">(</span><span class="s1">'/a/b/c.py'</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">'b/*.py'</span><span class="p">)</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">PurePath</span><span class="p">(</span><span class="s1">'/a/b/c.py'</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">'a/*.py'</span><span class="p">)</span> <span class="go">False</span> </pre></div> </div> <p>If <em>pattern</em> is absolute, the path must be absolute, and the whole path must match:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePath</span><span class="p">(</span><span class="s1">'/a.py'</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">'/*.py'</span><span class="p">)</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">PurePath</span><span class="p">(</span><span class="s1">'a/b.py'</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">'/*.py'</span><span class="p">)</span> <span class="go">False</span> </pre></div> </div> <p>As with other methods, case-sensitivity follows platform defaults:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'b.py'</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">'*.PY'</span><span class="p">)</span> <span class="go">False</span> <span class="gp">>>> </span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'b.py'</span><span class="p">)</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">'*.PY'</span><span class="p">)</span> <span class="go">True</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.PurePath.relative_to"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">relative_to</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PurePath.relative_to" title="Permalink to this definition">¶</a></dt> <dd><p>Compute a version of this path relative to the path represented by <em>other</em>. If it’s impossible, ValueError is raised:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PurePosixPath</span><span class="p">(</span><span class="s1">'/etc/passwd'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">relative_to</span><span class="p">(</span><span class="s1">'/'</span><span class="p">)</span> <span class="go">PurePosixPath('etc/passwd')</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">relative_to</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span> <span class="go">PurePosixPath('passwd')</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">relative_to</span><span class="p">(</span><span class="s1">'/usr'</span><span class="p">)</span> <span class="gt">Traceback (most recent call last):</span> File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span> File <span class="nb">"pathlib.py"</span>, line <span class="m">694</span>, in <span class="n">relative_to</span> <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span> <span class="nb">str</span><span class="p">(</span><span class="n">formatted</span><span class="p">)))</span> <span class="gr">ValueError</span>: <span class="n">'/etc/passwd' is not in the subpath of '/usr' OR one path is relative and the other absolute.</span> </pre></div> </div> <p>NOTE: This function is part of <a class="reference internal" href="#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePath</span></code></a> and works with strings. It does not check or access the underlying file structure.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.PurePath.with_name"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">with_name</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PurePath.with_name" title="Permalink to this definition">¶</a></dt> <dd><p>Return a new path with the <a class="reference internal" href="#pathlib.PurePath.name" title="pathlib.PurePath.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> changed. If the original path doesn’t have a name, ValueError is raised:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/Downloads/pathlib.tar.gz'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">with_name</span><span class="p">(</span><span class="s1">'setup.py'</span><span class="p">)</span> <span class="go">PureWindowsPath('c:/Downloads/setup.py')</span> <span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">with_name</span><span class="p">(</span><span class="s1">'setup.py'</span><span class="p">)</span> <span class="gt">Traceback (most recent call last):</span> File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span> File <span class="nb">"/home/antoine/cpython/default/Lib/pathlib.py"</span>, line <span class="m">751</span>, in <span class="n">with_name</span> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"</span><span class="si">%r</span><span class="s2"> has an empty name"</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="p">,))</span> <span class="gr">ValueError</span>: <span class="n">PureWindowsPath('c:/') has an empty name</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.PurePath.with_stem"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">with_stem</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">stem</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PurePath.with_stem" title="Permalink to this definition">¶</a></dt> <dd><p>Return a new path with the <a class="reference internal" href="#pathlib.PurePath.stem" title="pathlib.PurePath.stem"><code class="xref py py-attr docutils literal notranslate"><span class="pre">stem</span></code></a> changed. If the original path doesn’t have a name, ValueError is raised:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/Downloads/draft.txt'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">with_stem</span><span class="p">(</span><span class="s1">'final'</span><span class="p">)</span> <span class="go">PureWindowsPath('c:/Downloads/final.txt')</span> <span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/Downloads/pathlib.tar.gz'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">with_stem</span><span class="p">(</span><span class="s1">'lib'</span><span class="p">)</span> <span class="go">PureWindowsPath('c:/Downloads/lib.gz')</span> <span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">with_stem</span><span class="p">(</span><span class="s1">''</span><span class="p">)</span> <span class="gt">Traceback (most recent call last):</span> File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span> File <span class="nb">"/home/antoine/cpython/default/Lib/pathlib.py"</span>, line <span class="m">861</span>, in <span class="n">with_stem</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">with_name</span><span class="p">(</span><span class="n">stem</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">suffix</span><span class="p">)</span> File <span class="nb">"/home/antoine/cpython/default/Lib/pathlib.py"</span>, line <span class="m">851</span>, in <span class="n">with_name</span> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"</span><span class="si">%r</span><span class="s2"> has an empty name"</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="p">,))</span> <span class="gr">ValueError</span>: <span class="n">PureWindowsPath('c:/') has an empty name</span> </pre></div> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.9.</span></p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.PurePath.with_suffix"> <span class="sig-prename descclassname"><span class="pre">PurePath.</span></span><span class="sig-name descname"><span class="pre">with_suffix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">suffix</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PurePath.with_suffix" title="Permalink to this definition">¶</a></dt> <dd><p>Return a new path with the <a class="reference internal" href="#pathlib.PurePath.suffix" title="pathlib.PurePath.suffix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">suffix</span></code></a> changed. If the original path doesn’t have a suffix, the new <em>suffix</em> is appended instead. If the <em>suffix</em> is an empty string, the original suffix is removed:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'c:/Downloads/pathlib.tar.gz'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">with_suffix</span><span class="p">(</span><span class="s1">'.bz2'</span><span class="p">)</span> <span class="go">PureWindowsPath('c:/Downloads/pathlib.tar.bz2')</span> <span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'README'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">with_suffix</span><span class="p">(</span><span class="s1">'.txt'</span><span class="p">)</span> <span class="go">PureWindowsPath('README.txt')</span> <span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PureWindowsPath</span><span class="p">(</span><span class="s1">'README.txt'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">with_suffix</span><span class="p">(</span><span class="s1">''</span><span class="p">)</span> <span class="go">PureWindowsPath('README')</span> </pre></div> </div> </dd></dl> </section> </section> <section id="concrete-paths"> <span id="id2"></span><h2>Concrete paths<a class="headerlink" href="#concrete-paths" title="Permalink to this headline">¶</a></h2> <p>Concrete paths are subclasses of the pure path classes. In addition to operations provided by the latter, they also provide methods to do system calls on path objects. There are three ways to instantiate concrete paths:</p> <dl class="py class"> <dt class="sig sig-object py" id="pathlib.Path"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pathlib.</span></span><span class="sig-name descname"><span class="pre">Path</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">pathsegments</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path" title="Permalink to this definition">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePath</span></code></a>, this class represents concrete paths of the system’s path flavour (instantiating it creates either a <a class="reference internal" href="#pathlib.PosixPath" title="pathlib.PosixPath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PosixPath</span></code></a> or a <a class="reference internal" href="#pathlib.WindowsPath" title="pathlib.WindowsPath"><code class="xref py py-class docutils literal notranslate"><span class="pre">WindowsPath</span></code></a>):</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">Path</span><span class="p">(</span><span class="s1">'setup.py'</span><span class="p">)</span> <span class="go">PosixPath('setup.py')</span> </pre></div> </div> <p><em>pathsegments</em> is specified similarly to <a class="reference internal" href="#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePath</span></code></a>.</p> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="pathlib.PosixPath"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pathlib.</span></span><span class="sig-name descname"><span class="pre">PosixPath</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">pathsegments</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.PosixPath" title="Permalink to this definition">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">Path</span></code></a> and <a class="reference internal" href="#pathlib.PurePosixPath" title="pathlib.PurePosixPath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePosixPath</span></code></a>, this class represents concrete non-Windows filesystem paths:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">PosixPath</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span> <span class="go">PosixPath('/etc')</span> </pre></div> </div> <p><em>pathsegments</em> is specified similarly to <a class="reference internal" href="#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePath</span></code></a>.</p> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="pathlib.WindowsPath"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pathlib.</span></span><span class="sig-name descname"><span class="pre">WindowsPath</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">pathsegments</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.WindowsPath" title="Permalink to this definition">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">Path</span></code></a> and <a class="reference internal" href="#pathlib.PureWindowsPath" title="pathlib.PureWindowsPath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PureWindowsPath</span></code></a>, this class represents concrete Windows filesystem paths:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">WindowsPath</span><span class="p">(</span><span class="s1">'c:/Program Files/'</span><span class="p">)</span> <span class="go">WindowsPath('c:/Program Files')</span> </pre></div> </div> <p><em>pathsegments</em> is specified similarly to <a class="reference internal" href="#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePath</span></code></a>.</p> </dd></dl> <p>You can only instantiate the class flavour that corresponds to your system (allowing system calls on non-compatible path flavours could lead to bugs or failures in your application):</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">os</span> <span class="gp">>>> </span><span class="n">os</span><span class="o">.</span><span class="n">name</span> <span class="go">'posix'</span> <span class="gp">>>> </span><span class="n">Path</span><span class="p">(</span><span class="s1">'setup.py'</span><span class="p">)</span> <span class="go">PosixPath('setup.py')</span> <span class="gp">>>> </span><span class="n">PosixPath</span><span class="p">(</span><span class="s1">'setup.py'</span><span class="p">)</span> <span class="go">PosixPath('setup.py')</span> <span class="gp">>>> </span><span class="n">WindowsPath</span><span class="p">(</span><span class="s1">'setup.py'</span><span class="p">)</span> <span class="gt">Traceback (most recent call last):</span> File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span> File <span class="nb">"pathlib.py"</span>, line <span class="m">798</span>, in <span class="n">__new__</span> <span class="o">%</span> <span class="p">(</span><span class="bp">cls</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,))</span> <span class="gr">NotImplementedError</span>: <span class="n">cannot instantiate 'WindowsPath' on your system</span> </pre></div> </div> <section id="methods"> <h3>Methods<a class="headerlink" href="#methods" title="Permalink to this headline">¶</a></h3> <p>Concrete paths provide the following methods in addition to pure paths methods. Many of these methods can raise an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> if a system call fails (for example because the path doesn’t exist).</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.8: </span><a class="reference internal" href="#pathlib.Path.exists" title="pathlib.Path.exists"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exists()</span></code></a>, <a class="reference internal" href="#pathlib.Path.is_dir" title="pathlib.Path.is_dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_dir()</span></code></a>, <a class="reference internal" href="#pathlib.Path.is_file" title="pathlib.Path.is_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_file()</span></code></a>, <a class="reference internal" href="#pathlib.Path.is_mount" title="pathlib.Path.is_mount"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_mount()</span></code></a>, <a class="reference internal" href="#pathlib.Path.is_symlink" title="pathlib.Path.is_symlink"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_symlink()</span></code></a>, <a class="reference internal" href="#pathlib.Path.is_block_device" title="pathlib.Path.is_block_device"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_block_device()</span></code></a>, <a class="reference internal" href="#pathlib.Path.is_char_device" title="pathlib.Path.is_char_device"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_char_device()</span></code></a>, <a class="reference internal" href="#pathlib.Path.is_fifo" title="pathlib.Path.is_fifo"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_fifo()</span></code></a>, <a class="reference internal" href="#pathlib.Path.is_socket" title="pathlib.Path.is_socket"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_socket()</span></code></a> now return <code class="docutils literal notranslate"><span class="pre">False</span></code> instead of raising an exception for paths that contain characters unrepresentable at the OS level.</p> </div> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.cwd"> <em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">cwd</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.cwd" title="Permalink to this definition">¶</a></dt> <dd><p>Return a new path object representing the current directory (as returned by <a class="reference internal" href="os.html#os.getcwd" title="os.getcwd"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.getcwd()</span></code></a>):</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">Path</span><span class="o">.</span><span class="n">cwd</span><span class="p">()</span> <span class="go">PosixPath('/home/antoine/pathlib')</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.home"> <em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">home</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.home" title="Permalink to this definition">¶</a></dt> <dd><p>Return a new path object representing the user’s home directory (as returned by <a class="reference internal" href="os.path.html#os.path.expanduser" title="os.path.expanduser"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.expanduser()</span></code></a> with <code class="docutils literal notranslate"><span class="pre">~</span></code> construct). If the home directory can’t be resolved, <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> is raised.</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">Path</span><span class="o">.</span><span class="n">home</span><span class="p">()</span> <span class="go">PosixPath('/home/antoine')</span> </pre></div> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.stat"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">stat</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.stat" title="Permalink to this definition">¶</a></dt> <dd><p>Return a <a class="reference internal" href="os.html#os.stat_result" title="os.stat_result"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.stat_result</span></code></a> object containing information about this path, like <a class="reference internal" href="os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a>. The result is looked up at each call to this method.</p> <p>This method normally follows symlinks; to stat a symlink add the argument <code class="docutils literal notranslate"><span class="pre">follow_symlinks=False</span></code>, or use <a class="reference internal" href="#pathlib.Path.lstat" title="pathlib.Path.lstat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">lstat()</span></code></a>.</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'setup.py'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">stat</span><span class="p">()</span><span class="o">.</span><span class="n">st_size</span> <span class="go">956</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">stat</span><span class="p">()</span><span class="o">.</span><span class="n">st_mtime</span> <span class="go">1327883547.852554</span> </pre></div> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.10: </span>The <em>follow_symlinks</em> parameter was added.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.chmod"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">chmod</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.chmod" title="Permalink to this definition">¶</a></dt> <dd><p>Change the file mode and permissions, like <a class="reference internal" href="os.html#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.chmod()</span></code></a>.</p> <p>This method normally follows symlinks. Some Unix flavours support changing permissions on the symlink itself; on these platforms you may add the argument <code class="docutils literal notranslate"><span class="pre">follow_symlinks=False</span></code>, or use <a class="reference internal" href="#pathlib.Path.lchmod" title="pathlib.Path.lchmod"><code class="xref py py-meth docutils literal notranslate"><span class="pre">lchmod()</span></code></a>.</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'setup.py'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">stat</span><span class="p">()</span><span class="o">.</span><span class="n">st_mode</span> <span class="go">33277</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">chmod</span><span class="p">(</span><span class="mo">0o444</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">stat</span><span class="p">()</span><span class="o">.</span><span class="n">st_mode</span> <span class="go">33060</span> </pre></div> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.10: </span>The <em>follow_symlinks</em> parameter was added.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.exists"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">exists</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.exists" title="Permalink to this definition">¶</a></dt> <dd><p>Whether the path points to an existing file or directory:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">Path</span><span class="p">(</span><span class="s1">'.'</span><span class="p">)</span><span class="o">.</span><span class="n">exists</span><span class="p">()</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">Path</span><span class="p">(</span><span class="s1">'setup.py'</span><span class="p">)</span><span class="o">.</span><span class="n">exists</span><span class="p">()</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">Path</span><span class="p">(</span><span class="s1">'/etc'</span><span class="p">)</span><span class="o">.</span><span class="n">exists</span><span class="p">()</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">Path</span><span class="p">(</span><span class="s1">'nonexistentfile'</span><span class="p">)</span><span class="o">.</span><span class="n">exists</span><span class="p">()</span> <span class="go">False</span> </pre></div> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <p>If the path points to a symlink, <a class="reference internal" href="#pathlib.Path.exists" title="pathlib.Path.exists"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exists()</span></code></a> returns whether the symlink <em>points to</em> an existing file or directory.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.expanduser"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">expanduser</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.expanduser" title="Permalink to this definition">¶</a></dt> <dd><p>Return a new path with expanded <code class="docutils literal notranslate"><span class="pre">~</span></code> and <code class="docutils literal notranslate"><span class="pre">~user</span></code> constructs, as returned by <a class="reference internal" href="os.path.html#os.path.expanduser" title="os.path.expanduser"><code class="xref py py-meth docutils literal notranslate"><span class="pre">os.path.expanduser()</span></code></a>. If a home directory can’t be resolved, <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> is raised.</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">PosixPath</span><span class="p">(</span><span class="s1">'~/films/Monty Python'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">expanduser</span><span class="p">()</span> <span class="go">PosixPath('/home/eric/films/Monty Python')</span> </pre></div> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.glob"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">glob</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pattern</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.glob" title="Permalink to this definition">¶</a></dt> <dd><p>Glob the given relative <em>pattern</em> in the directory represented by this path, yielding all matching files (of any kind):</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">sorted</span><span class="p">(</span><span class="n">Path</span><span class="p">(</span><span class="s1">'.'</span><span class="p">)</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="s1">'*.py'</span><span class="p">))</span> <span class="go">[PosixPath('pathlib.py'), PosixPath('setup.py'), PosixPath('test_pathlib.py')]</span> <span class="gp">>>> </span><span class="nb">sorted</span><span class="p">(</span><span class="n">Path</span><span class="p">(</span><span class="s1">'.'</span><span class="p">)</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="s1">'*/*.py'</span><span class="p">))</span> <span class="go">[PosixPath('docs/conf.py')]</span> </pre></div> </div> <p>Patterns are the same as for <a class="reference internal" href="fnmatch.html#module-fnmatch" title="fnmatch: Unix shell style filename pattern matching."><code class="xref py py-mod docutils literal notranslate"><span class="pre">fnmatch</span></code></a>, with the addition of “<code class="docutils literal notranslate"><span class="pre">**</span></code>” which means “this directory and all subdirectories, recursively”. In other words, it enables recursive globbing:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">sorted</span><span class="p">(</span><span class="n">Path</span><span class="p">(</span><span class="s1">'.'</span><span class="p">)</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="s1">'**/*.py'</span><span class="p">))</span> <span class="go">[PosixPath('build/lib/pathlib.py'),</span> <span class="go"> PosixPath('docs/conf.py'),</span> <span class="go"> PosixPath('pathlib.py'),</span> <span class="go"> PosixPath('setup.py'),</span> <span class="go"> PosixPath('test_pathlib.py')]</span> </pre></div> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <p>Using the “<code class="docutils literal notranslate"><span class="pre">**</span></code>” pattern in large directory trees may consume an inordinate amount of time.</p> </div> <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">pathlib.Path.glob</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">self</span></code>, <code class="docutils literal notranslate"><span class="pre">pattern</span></code>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.group"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">group</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.group" title="Permalink to this definition">¶</a></dt> <dd><p>Return the name of the group owning the file. <a class="reference internal" href="exceptions.html#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> is raised if the file’s gid isn’t found in the system database.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.is_dir"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">is_dir</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.is_dir" title="Permalink to this definition">¶</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the path points to a directory (or a symbolic link pointing to a directory), <code class="docutils literal notranslate"><span class="pre">False</span></code> if it points to another kind of file.</p> <p><code class="docutils literal notranslate"><span class="pre">False</span></code> is also returned if the path doesn’t exist or is a broken symlink; other errors (such as permission errors) are propagated.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.is_file"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">is_file</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.is_file" title="Permalink to this definition">¶</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the path points to a regular file (or a symbolic link pointing to a regular file), <code class="docutils literal notranslate"><span class="pre">False</span></code> if it points to another kind of file.</p> <p><code class="docutils literal notranslate"><span class="pre">False</span></code> is also returned if the path doesn’t exist or is a broken symlink; other errors (such as permission errors) are propagated.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.is_mount"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">is_mount</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.is_mount" title="Permalink to this definition">¶</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the path is a <em class="dfn">mount point</em>: a point in a file system where a different file system has been mounted. On POSIX, the function checks whether <em>path</em>’s parent, <code class="file docutils literal notranslate"><span class="pre">path/..</span></code>, is on a different device than <em>path</em>, or whether <code class="file docutils literal notranslate"><span class="pre">path/..</span></code> and <em>path</em> point to the same i-node on the same device — this should detect mount points for all Unix and POSIX variants. Not implemented on Windows.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.7.</span></p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.is_symlink"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">is_symlink</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.is_symlink" title="Permalink to this definition">¶</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the path points to a symbolic link, <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.</p> <p><code class="docutils literal notranslate"><span class="pre">False</span></code> is also returned if the path doesn’t exist; other errors (such as permission errors) are propagated.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.is_socket"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">is_socket</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.is_socket" title="Permalink to this definition">¶</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the path points to a Unix socket (or a symbolic link pointing to a Unix socket), <code class="docutils literal notranslate"><span class="pre">False</span></code> if it points to another kind of file.</p> <p><code class="docutils literal notranslate"><span class="pre">False</span></code> is also returned if the path doesn’t exist or is a broken symlink; other errors (such as permission errors) are propagated.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.is_fifo"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">is_fifo</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.is_fifo" title="Permalink to this definition">¶</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the path points to a FIFO (or a symbolic link pointing to a FIFO), <code class="docutils literal notranslate"><span class="pre">False</span></code> if it points to another kind of file.</p> <p><code class="docutils literal notranslate"><span class="pre">False</span></code> is also returned if the path doesn’t exist or is a broken symlink; other errors (such as permission errors) are propagated.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.is_block_device"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">is_block_device</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.is_block_device" title="Permalink to this definition">¶</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the path points to a block device (or a symbolic link pointing to a block device), <code class="docutils literal notranslate"><span class="pre">False</span></code> if it points to another kind of file.</p> <p><code class="docutils literal notranslate"><span class="pre">False</span></code> is also returned if the path doesn’t exist or is a broken symlink; other errors (such as permission errors) are propagated.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.is_char_device"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">is_char_device</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.is_char_device" title="Permalink to this definition">¶</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the path points to a character device (or a symbolic link pointing to a character device), <code class="docutils literal notranslate"><span class="pre">False</span></code> if it points to another kind of file.</p> <p><code class="docutils literal notranslate"><span class="pre">False</span></code> is also returned if the path doesn’t exist or is a broken symlink; other errors (such as permission errors) are propagated.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.iterdir"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">iterdir</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.iterdir" title="Permalink to this definition">¶</a></dt> <dd><p>When the path points to a directory, yield path objects of the directory contents:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'docs'</span><span class="p">)</span> <span class="gp">>>> </span><span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">iterdir</span><span class="p">():</span> <span class="n">child</span> <span class="gp">...</span> <span class="go">PosixPath('docs/conf.py')</span> <span class="go">PosixPath('docs/_templates')</span> <span class="go">PosixPath('docs/make.bat')</span> <span class="go">PosixPath('docs/index.rst')</span> <span class="go">PosixPath('docs/_build')</span> <span class="go">PosixPath('docs/_static')</span> <span class="go">PosixPath('docs/Makefile')</span> </pre></div> </div> <p>The children are yielded in arbitrary order, and the special entries <code class="docutils literal notranslate"><span class="pre">'.'</span></code> and <code class="docutils literal notranslate"><span class="pre">'..'</span></code> are not included. If a file is removed from or added to the directory after creating the iterator, whether a path object for that file be included is unspecified.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.lchmod"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">lchmod</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.lchmod" title="Permalink to this definition">¶</a></dt> <dd><p>Like <a class="reference internal" href="#pathlib.Path.chmod" title="pathlib.Path.chmod"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.chmod()</span></code></a> but, if the path points to a symbolic link, the symbolic link’s mode is changed rather than its target’s.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.lstat"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">lstat</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.lstat" title="Permalink to this definition">¶</a></dt> <dd><p>Like <a class="reference internal" href="#pathlib.Path.stat" title="pathlib.Path.stat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.stat()</span></code></a> but, if the path points to a symbolic link, return the symbolic link’s information rather than its target’s.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.mkdir"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">mkdir</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0o777</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">parents</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exist_ok</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.mkdir" title="Permalink to this definition">¶</a></dt> <dd><p>Create a new directory at this given path. If <em>mode</em> is given, it is combined with the process’ <code class="docutils literal notranslate"><span class="pre">umask</span></code> value to determine the file mode and access flags. If the path already exists, <a class="reference internal" href="exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a> is raised.</p> <p>If <em>parents</em> is true, any missing parents of this path are created as needed; they are created with the default permissions without taking <em>mode</em> into account (mimicking the POSIX <code class="docutils literal notranslate"><span class="pre">mkdir</span> <span class="pre">-p</span></code> command).</p> <p>If <em>parents</em> is false (the default), a missing parent raises <a class="reference internal" href="exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a>.</p> <p>If <em>exist_ok</em> is false (the default), <a class="reference internal" href="exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a> is raised if the target directory already exists.</p> <p>If <em>exist_ok</em> is true, <a class="reference internal" href="exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a> exceptions will be ignored (same behavior as the POSIX <code class="docutils literal notranslate"><span class="pre">mkdir</span> <span class="pre">-p</span></code> command), but only if the last path component is not an existing non-directory file.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.5: </span>The <em>exist_ok</em> parameter was added.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.open"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">open</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'r'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">buffering</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-</span> <span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">errors</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">newline</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.open" title="Permalink to this definition">¶</a></dt> <dd><p>Open the file pointed to by the path, like the built-in <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> function does:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'setup.py'</span><span class="p">)</span> <span class="gp">>>> </span><span class="k">with</span> <span class="n">p</span><span class="o">.</span><span class="n">open</span><span class="p">()</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="gp">... </span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span> <span class="gp">...</span> <span class="go">'#!/usr/bin/env python3\n'</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.owner"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">owner</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.owner" title="Permalink to this definition">¶</a></dt> <dd><p>Return the name of the user owning the file. <a class="reference internal" href="exceptions.html#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> is raised if the file’s uid isn’t found in the system database.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.read_bytes"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">read_bytes</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.read_bytes" title="Permalink to this definition">¶</a></dt> <dd><p>Return the binary contents of the pointed-to file as a bytes object:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'my_binary_file'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">write_bytes</span><span class="p">(</span><span class="sa">b</span><span class="s1">'Binary file contents'</span><span class="p">)</span> <span class="go">20</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">read_bytes</span><span class="p">()</span> <span class="go">b'Binary file contents'</span> </pre></div> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.read_text"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">read_text</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">errors</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.read_text" title="Permalink to this definition">¶</a></dt> <dd><p>Return the decoded contents of the pointed-to file as a string:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'my_text_file'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">write_text</span><span class="p">(</span><span class="s1">'Text file contents'</span><span class="p">)</span> <span class="go">18</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">read_text</span><span class="p">()</span> <span class="go">'Text file contents'</span> </pre></div> </div> <p>The file is opened and then closed. The optional parameters have the same meaning as in <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.readlink"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">readlink</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.readlink" title="Permalink to this definition">¶</a></dt> <dd><p>Return the path to which the symbolic link points (as returned by <a class="reference internal" href="os.html#os.readlink" title="os.readlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.readlink()</span></code></a>):</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'mylink'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">symlink_to</span><span class="p">(</span><span class="s1">'setup.py'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">readlink</span><span class="p">()</span> <span class="go">PosixPath('setup.py')</span> </pre></div> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.9.</span></p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.rename"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">rename</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">target</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.rename" title="Permalink to this definition">¶</a></dt> <dd><p>Rename this file or directory to the given <em>target</em>, and return a new Path instance pointing to <em>target</em>. On Unix, if <em>target</em> exists and is a file, it will be replaced silently if the user has permission. On Windows, if <em>target</em> exists, <a class="reference internal" href="exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a> will be raised. <em>target</em> can be either a string or another path object:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">'w'</span><span class="p">)</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'some text'</span><span class="p">)</span> <span class="go">9</span> <span class="gp">>>> </span><span class="n">target</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'bar'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">rename</span><span class="p">(</span><span class="n">target</span><span class="p">)</span> <span class="go">PosixPath('bar')</span> <span class="gp">>>> </span><span class="n">target</span><span class="o">.</span><span class="n">open</span><span class="p">()</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> <span class="go">'some text'</span> </pre></div> </div> <p>The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, <em>not</em> the directory of the Path object.</p> <p>It is implemented in terms of <a class="reference internal" href="os.html#os.rename" title="os.rename"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.rename()</span></code></a> and gives the same guarantees.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.8: </span>Added return value, return the new Path instance.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.replace"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">replace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">target</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.replace" title="Permalink to this definition">¶</a></dt> <dd><p>Rename this file or directory to the given <em>target</em>, and return a new Path instance pointing to <em>target</em>. If <em>target</em> points to an existing file or empty directory, it will be unconditionally replaced.</p> <p>The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, <em>not</em> the directory of the Path object.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.8: </span>Added return value, return the new Path instance.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.resolve"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">resolve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">strict</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.resolve" title="Permalink to this definition">¶</a></dt> <dd><p>Make the path absolute, resolving any symlinks. A new path object is returned:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">p</span> <span class="go">PosixPath('.')</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">resolve</span><span class="p">()</span> <span class="go">PosixPath('/home/antoine/pathlib')</span> </pre></div> </div> <p>“<code class="docutils literal notranslate"><span class="pre">..</span></code>” components are also eliminated (this is the only method to do so):</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'docs/../setup.py'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">resolve</span><span class="p">()</span> <span class="go">PosixPath('/home/antoine/pathlib/setup.py')</span> </pre></div> </div> <p>If the path doesn’t exist and <em>strict</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, <a class="reference internal" href="exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a> is raised. If <em>strict</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>, the path is resolved as far as possible and any remainder is appended without checking whether it exists. If an infinite loop is encountered along the resolution path, <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> is raised.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.6: </span>The <em>strict</em> argument (pre-3.6 behavior is strict).</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.rglob"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">rglob</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pattern</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.rglob" title="Permalink to this definition">¶</a></dt> <dd><p>This is like calling <a class="reference internal" href="#pathlib.Path.glob" title="pathlib.Path.glob"><code class="xref py py-func docutils literal notranslate"><span class="pre">Path.glob()</span></code></a> with “<code class="docutils literal notranslate"><span class="pre">**/</span></code>” added in front of the given relative <em>pattern</em>:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">sorted</span><span class="p">(</span><span class="n">Path</span><span class="p">()</span><span class="o">.</span><span class="n">rglob</span><span class="p">(</span><span class="s2">"*.py"</span><span class="p">))</span> <span class="go">[PosixPath('build/lib/pathlib.py'),</span> <span class="go"> PosixPath('docs/conf.py'),</span> <span class="go"> PosixPath('pathlib.py'),</span> <span class="go"> PosixPath('setup.py'),</span> <span class="go"> PosixPath('test_pathlib.py')]</span> </pre></div> </div> <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">pathlib.Path.rglob</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">self</span></code>, <code class="docutils literal notranslate"><span class="pre">pattern</span></code>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.rmdir"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">rmdir</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.rmdir" title="Permalink to this definition">¶</a></dt> <dd><p>Remove this directory. The directory must be empty.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.samefile"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">samefile</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other_path</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.samefile" title="Permalink to this definition">¶</a></dt> <dd><p>Return whether this path points to the same file as <em>other_path</em>, which can be either a Path object, or a string. The semantics are similar to <a class="reference internal" href="os.path.html#os.path.samefile" title="os.path.samefile"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.samefile()</span></code></a> and <a class="reference internal" href="os.path.html#os.path.samestat" title="os.path.samestat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.samestat()</span></code></a>.</p> <p>An <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> can be raised if either file cannot be accessed for some reason.</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'spam'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">q</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'eggs'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">samefile</span><span class="p">(</span><span class="n">q</span><span class="p">)</span> <span class="go">False</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">samefile</span><span class="p">(</span><span class="s1">'spam'</span><span class="p">)</span> <span class="go">True</span> </pre></div> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.symlink_to"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">symlink_to</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">target</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">target_is_directory</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.symlink_to" title="Permalink to this definition">¶</a></dt> <dd><p>Make this path a symbolic link to <em>target</em>. Under Windows, <em>target_is_directory</em> must be true (default <code class="docutils literal notranslate"><span class="pre">False</span></code>) if the link’s target is a directory. Under POSIX, <em>target_is_directory</em>’s value is ignored.</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'mylink'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">symlink_to</span><span class="p">(</span><span class="s1">'setup.py'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">resolve</span><span class="p">()</span> <span class="go">PosixPath('/home/antoine/pathlib/setup.py')</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">stat</span><span class="p">()</span><span class="o">.</span><span class="n">st_size</span> <span class="go">956</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">lstat</span><span class="p">()</span><span class="o">.</span><span class="n">st_size</span> <span class="go">8</span> </pre></div> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <p>The order of arguments (link, target) is the reverse of <a class="reference internal" href="os.html#os.symlink" title="os.symlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.symlink()</span></code></a>’s.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.hardlink_to"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">hardlink_to</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">target</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.hardlink_to" title="Permalink to this definition">¶</a></dt> <dd><p>Make this path a hard link to the same file as <em>target</em>.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>The order of arguments (link, target) is the reverse of <a class="reference internal" href="os.html#os.link" title="os.link"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.link()</span></code></a>’s.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.10.</span></p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.link_to"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">link_to</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">target</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.link_to" title="Permalink to this definition">¶</a></dt> <dd><p>Make <em>target</em> a hard link to this path.</p> <div class="admonition warning"> <p class="admonition-title">Warning</p> <p>This function does not make this path a hard link to <em>target</em>, despite the implication of the function and argument names. The argument order (target, link) is the reverse of <a class="reference internal" href="#pathlib.Path.symlink_to" title="pathlib.Path.symlink_to"><code class="xref py py-func docutils literal notranslate"><span class="pre">Path.symlink_to()</span></code></a> and <a class="reference internal" href="#pathlib.Path.hardlink_to" title="pathlib.Path.hardlink_to"><code class="xref py py-func docutils literal notranslate"><span class="pre">Path.hardlink_to()</span></code></a>, but matches that of <a class="reference internal" href="os.html#os.link" title="os.link"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.link()</span></code></a>.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.8.</span></p> </div> <div class="deprecated"> <p><span class="versionmodified deprecated">Deprecated since version 3.10: </span>This method is deprecated in favor of <a class="reference internal" href="#pathlib.Path.hardlink_to" title="pathlib.Path.hardlink_to"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.hardlink_to()</span></code></a>, as the argument order of <a class="reference internal" href="#pathlib.Path.link_to" title="pathlib.Path.link_to"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.link_to()</span></code></a> does not match that of <a class="reference internal" href="#pathlib.Path.symlink_to" title="pathlib.Path.symlink_to"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.symlink_to()</span></code></a>.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.touch"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">touch</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0o666</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exist_ok</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.touch" title="Permalink to this definition">¶</a></dt> <dd><p>Create a file at this given path. If <em>mode</em> is given, it is combined with the process’ <code class="docutils literal notranslate"><span class="pre">umask</span></code> value to determine the file mode and access flags. If the file already exists, the function succeeds if <em>exist_ok</em> is true (and its modification time is updated to the current time), otherwise <a class="reference internal" href="exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a> is raised.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.unlink"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">unlink</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">missing_ok</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.unlink" title="Permalink to this definition">¶</a></dt> <dd><p>Remove this file or symbolic link. If the path points to a directory, use <a class="reference internal" href="#pathlib.Path.rmdir" title="pathlib.Path.rmdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">Path.rmdir()</span></code></a> instead.</p> <p>If <em>missing_ok</em> is false (the default), <a class="reference internal" href="exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a> is raised if the path does not exist.</p> <p>If <em>missing_ok</em> is true, <a class="reference internal" href="exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a> exceptions will be ignored (same behavior as the POSIX <code class="docutils literal notranslate"><span class="pre">rm</span> <span class="pre">-f</span></code> command).</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.8: </span>The <em>missing_ok</em> parameter was added.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.write_bytes"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">write_bytes</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.write_bytes" title="Permalink to this definition">¶</a></dt> <dd><p>Open the file pointed to in bytes mode, write <em>data</em> to it, and close the file:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'my_binary_file'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">write_bytes</span><span class="p">(</span><span class="sa">b</span><span class="s1">'Binary file contents'</span><span class="p">)</span> <span class="go">20</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">read_bytes</span><span class="p">()</span> <span class="go">b'Binary file contents'</span> </pre></div> </div> <p>An existing file of the same name is overwritten.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="pathlib.Path.write_text"> <span class="sig-prename descclassname"><span class="pre">Path.</span></span><span class="sig-name descname"><span class="pre">write_text</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">errors</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">newline</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.write_text" title="Permalink to this definition">¶</a></dt> <dd><p>Open the file pointed to in text mode, write <em>data</em> to it, and close the file:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="s1">'my_text_file'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">write_text</span><span class="p">(</span><span class="s1">'Text file contents'</span><span class="p">)</span> <span class="go">18</span> <span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">read_text</span><span class="p">()</span> <span class="go">'Text file contents'</span> </pre></div> </div> <p>An existing file of the same name is overwritten. The optional parameters have the same meaning as in <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.10: </span>The <em>newline</em> parameter was added.</p> </div> </dd></dl> </section> </section> <section id="correspondence-to-tools-in-the-os-module"> <h2>Correspondence to tools in the <a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module<a class="headerlink" href="#correspondence-to-tools-in-the-os-module" title="Permalink to this headline">¶</a></h2> <p>Below is a table mapping various <a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> functions to their corresponding <a class="reference internal" href="#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePath</span></code></a>/<a class="reference internal" href="#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">Path</span></code></a> equivalent.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>Not all pairs of functions/methods below are equivalent. Some of them, despite having some overlapping use-cases, have different semantics. They include <a class="reference internal" href="os.path.html#os.path.abspath" title="os.path.abspath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.abspath()</span></code></a> and <a class="reference internal" href="#pathlib.Path.resolve" title="pathlib.Path.resolve"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.resolve()</span></code></a>, <a class="reference internal" href="os.path.html#os.path.relpath" title="os.path.relpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.relpath()</span></code></a> and <a class="reference internal" href="#pathlib.PurePath.relative_to" title="pathlib.PurePath.relative_to"><code class="xref py py-meth docutils literal notranslate"><span class="pre">PurePath.relative_to()</span></code></a>.</p> </div> <table class="docutils align-default"> <colgroup> <col style="width: 52%" /> <col style="width: 48%" /> </colgroup> <thead> <tr class="row-odd"><th class="head"><p><a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> and <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a></p></th> <th class="head"><p><a class="reference internal" href="#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a></p></th> </tr> </thead> <tbody> <tr class="row-even"><td><p><a class="reference internal" href="os.path.html#os.path.abspath" title="os.path.abspath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.abspath()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.resolve" title="pathlib.Path.resolve"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.resolve()</span></code></a> <a class="footnote-reference brackets" href="#id5" id="id3">1</a></p></td> </tr> <tr class="row-odd"><td><p><a class="reference internal" href="os.html#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.chmod()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.chmod" title="pathlib.Path.chmod"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.chmod()</span></code></a></p></td> </tr> <tr class="row-even"><td><p><a class="reference internal" href="os.html#os.mkdir" title="os.mkdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.mkdir()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.mkdir" title="pathlib.Path.mkdir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.mkdir()</span></code></a></p></td> </tr> <tr class="row-odd"><td><p><a class="reference internal" href="os.html#os.makedirs" title="os.makedirs"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.makedirs()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.mkdir" title="pathlib.Path.mkdir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.mkdir()</span></code></a></p></td> </tr> <tr class="row-even"><td><p><a class="reference internal" href="os.html#os.rename" title="os.rename"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.rename()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.rename" title="pathlib.Path.rename"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.rename()</span></code></a></p></td> </tr> <tr class="row-odd"><td><p><a class="reference internal" href="os.html#os.replace" title="os.replace"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.replace()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.replace" title="pathlib.Path.replace"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.replace()</span></code></a></p></td> </tr> <tr class="row-even"><td><p><a class="reference internal" href="os.html#os.rmdir" title="os.rmdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.rmdir()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.rmdir" title="pathlib.Path.rmdir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.rmdir()</span></code></a></p></td> </tr> <tr class="row-odd"><td><p><a class="reference internal" href="os.html#os.remove" title="os.remove"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.remove()</span></code></a>, <a class="reference internal" href="os.html#os.unlink" title="os.unlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.unlink()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.unlink" title="pathlib.Path.unlink"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.unlink()</span></code></a></p></td> </tr> <tr class="row-even"><td><p><a class="reference internal" href="os.html#os.getcwd" title="os.getcwd"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.getcwd()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.cwd" title="pathlib.Path.cwd"><code class="xref py py-func docutils literal notranslate"><span class="pre">Path.cwd()</span></code></a></p></td> </tr> <tr class="row-odd"><td><p><a class="reference internal" href="os.path.html#os.path.exists" title="os.path.exists"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.exists()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.exists" title="pathlib.Path.exists"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.exists()</span></code></a></p></td> </tr> <tr class="row-even"><td><p><a class="reference internal" href="os.path.html#os.path.expanduser" title="os.path.expanduser"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.expanduser()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.expanduser" title="pathlib.Path.expanduser"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.expanduser()</span></code></a> and <a class="reference internal" href="#pathlib.Path.home" title="pathlib.Path.home"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.home()</span></code></a></p></td> </tr> <tr class="row-odd"><td><p><a class="reference internal" href="os.html#os.listdir" title="os.listdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listdir()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.iterdir" title="pathlib.Path.iterdir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.iterdir()</span></code></a></p></td> </tr> <tr class="row-even"><td><p><a class="reference internal" href="os.path.html#os.path.isdir" title="os.path.isdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.isdir()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.is_dir" title="pathlib.Path.is_dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.is_dir()</span></code></a></p></td> </tr> <tr class="row-odd"><td><p><a class="reference internal" href="os.path.html#os.path.isfile" title="os.path.isfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.isfile()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.is_file" title="pathlib.Path.is_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.is_file()</span></code></a></p></td> </tr> <tr class="row-even"><td><p><a class="reference internal" href="os.path.html#os.path.islink" title="os.path.islink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.islink()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.is_symlink" title="pathlib.Path.is_symlink"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.is_symlink()</span></code></a></p></td> </tr> <tr class="row-odd"><td><p><a class="reference internal" href="os.html#os.link" title="os.link"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.link()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.hardlink_to" title="pathlib.Path.hardlink_to"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.hardlink_to()</span></code></a></p></td> </tr> <tr class="row-even"><td><p><a class="reference internal" href="os.html#os.symlink" title="os.symlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.symlink()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.symlink_to" title="pathlib.Path.symlink_to"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.symlink_to()</span></code></a></p></td> </tr> <tr class="row-odd"><td><p><a class="reference internal" href="os.html#os.readlink" title="os.readlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.readlink()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.readlink" title="pathlib.Path.readlink"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.readlink()</span></code></a></p></td> </tr> <tr class="row-even"><td><p><a class="reference internal" href="os.path.html#os.path.relpath" title="os.path.relpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.relpath()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.PurePath.relative_to" title="pathlib.PurePath.relative_to"><code class="xref py py-meth docutils literal notranslate"><span class="pre">PurePath.relative_to()</span></code></a> <a class="footnote-reference brackets" href="#id6" id="id4">2</a></p></td> </tr> <tr class="row-odd"><td><p><a class="reference internal" href="os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.stat" title="pathlib.Path.stat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.stat()</span></code></a>, <a class="reference internal" href="#pathlib.Path.owner" title="pathlib.Path.owner"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.owner()</span></code></a>, <a class="reference internal" href="#pathlib.Path.group" title="pathlib.Path.group"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.group()</span></code></a></p></td> </tr> <tr class="row-even"><td><p><a class="reference internal" href="os.path.html#os.path.isabs" title="os.path.isabs"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.isabs()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.PurePath.is_absolute" title="pathlib.PurePath.is_absolute"><code class="xref py py-meth docutils literal notranslate"><span class="pre">PurePath.is_absolute()</span></code></a></p></td> </tr> <tr class="row-odd"><td><p><a class="reference internal" href="os.path.html#os.path.join" title="os.path.join"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.join()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.PurePath.joinpath" title="pathlib.PurePath.joinpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">PurePath.joinpath()</span></code></a></p></td> </tr> <tr class="row-even"><td><p><a class="reference internal" href="os.path.html#os.path.basename" title="os.path.basename"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.basename()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.PurePath.name" title="pathlib.PurePath.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">PurePath.name</span></code></a></p></td> </tr> <tr class="row-odd"><td><p><a class="reference internal" href="os.path.html#os.path.dirname" title="os.path.dirname"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.dirname()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.PurePath.parent" title="pathlib.PurePath.parent"><code class="xref py py-attr docutils literal notranslate"><span class="pre">PurePath.parent</span></code></a></p></td> </tr> <tr class="row-even"><td><p><a class="reference internal" href="os.path.html#os.path.samefile" title="os.path.samefile"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.samefile()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.Path.samefile" title="pathlib.Path.samefile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.samefile()</span></code></a></p></td> </tr> <tr class="row-odd"><td><p><a class="reference internal" href="os.path.html#os.path.splitext" title="os.path.splitext"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.splitext()</span></code></a></p></td> <td><p><a class="reference internal" href="#pathlib.PurePath.stem" title="pathlib.PurePath.stem"><code class="xref py py-attr docutils literal notranslate"><span class="pre">PurePath.stem</span></code></a> and <a class="reference internal" href="#pathlib.PurePath.suffix" title="pathlib.PurePath.suffix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">PurePath.suffix</span></code></a></p></td> </tr> </tbody> </table> <p class="rubric">Footnotes</p> <dl class="footnote brackets"> <dt class="label" id="id5"><span class="brackets"><a class="fn-backref" href="#id3">1</a></span></dt> <dd><p><a class="reference internal" href="os.path.html#os.path.abspath" title="os.path.abspath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.abspath()</span></code></a> does not resolve symbolic links while <a class="reference internal" href="#pathlib.Path.resolve" title="pathlib.Path.resolve"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.resolve()</span></code></a> does.</p> </dd> <dt class="label" id="id6"><span class="brackets"><a class="fn-backref" href="#id4">2</a></span></dt> <dd><p><a class="reference internal" href="#pathlib.PurePath.relative_to" title="pathlib.PurePath.relative_to"><code class="xref py py-meth docutils literal notranslate"><span class="pre">PurePath.relative_to()</span></code></a> requires <code class="docutils literal notranslate"><span class="pre">self</span></code> to be the subpath of the argument, but <a class="reference internal" href="os.path.html#os.path.relpath" title="os.path.relpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.relpath()</span></code></a> does not.</p> </dd> </dl> </section> </section> <div class="clearer"></div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">Table of Contents</a></h3> <ul> <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code> — Object-oriented filesystem paths</a><ul> <li><a class="reference internal" href="#basic-use">Basic use</a></li> <li><a class="reference internal" href="#pure-paths">Pure paths</a><ul> <li><a class="reference internal" href="#general-properties">General properties</a></li> <li><a class="reference internal" href="#operators">Operators</a></li> <li><a class="reference internal" href="#accessing-individual-parts">Accessing individual parts</a></li> <li><a class="reference internal" href="#methods-and-properties">Methods and properties</a></li> </ul> </li> <li><a class="reference internal" href="#concrete-paths">Concrete paths</a><ul> <li><a class="reference internal" href="#methods">Methods</a></li> </ul> </li> <li><a class="reference internal" href="#correspondence-to-tools-in-the-os-module">Correspondence to tools in the <code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code> module</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="filesys.html" title="previous chapter">File and Directory Access</a></p> <h4>Next topic</h4> <p class="topless"><a href="os.path.html" title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code> — Common pathname manipulations</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li> <a href="https://github.com/python/cpython/blob/3.10/Doc/library/pathlib.rst" rel="nofollow">Show Source </a> </li> </ul> </div> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="os.path.html" title="os.path — Common pathname manipulations" >next</a> |</li> <li class="right" > <a href="filesys.html" title="File and Directory Access" >previous</a> |</li> <li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li class="switchers"> <div class="language_switcher_placeholder"></div> <div class="version_switcher_placeholder"></div> </li> <li> </li> <li id="cpython-language-and-version"> <a href="../index.html">3.10.12 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="filesys.html" >File and Directory Access</a> »</li> <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code> — Object-oriented filesystem paths</a></li> <li class="right"> <div class="inline-search" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" aria-label="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> | </li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 2001-2026, Python Software Foundation. <br /> This page is licensed under the Python Software Foundation License Version 2. <br /> Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License. <br /> See <a href="/license.html">History and License</a> for more information.<br /> <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> <br /> Last updated on January 26, 2026. <a href="/bugs.html">Found a bug</a>? <br /> Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.3.2. </div> </body> </html>
Close