Linux server1.hosting4iran.com 4.18.0-553.123.2.el8_10.x86_64 #1 SMP Thu May 7 15:28:41 EDT 2026 x86_64
LiteSpeed
Server IP : 185.208.174.156 & Your IP : 216.73.216.74
Domains : 326 Domain
User : satitravel
Terminal
Auto Root
Create File
Create Folder
Localroot Suggester
Backdoor Destroyer
Readme
/
usr /
share /
doc /
python3-docs /
html /
library /
Delete
Unzip
Name
Size
Permission
Date
Action
2to3.html
60.26
KB
-rw-r--r--
2023-12-18 11:36
__future__.html
15.42
KB
-rw-r--r--
2023-12-18 11:36
__main__.html
8.81
KB
-rw-r--r--
2023-12-18 11:36
_dummy_thread.html
8.98
KB
-rw-r--r--
2023-12-18 11:36
_thread.html
22.06
KB
-rw-r--r--
2023-12-18 11:36
abc.html
40.42
KB
-rw-r--r--
2023-12-18 11:36
aifc.html
27.46
KB
-rw-r--r--
2023-12-18 11:36
allos.html
31.48
KB
-rw-r--r--
2023-12-18 11:36
archiving.html
11.71
KB
-rw-r--r--
2023-12-18 11:36
argparse.html
268.54
KB
-rw-r--r--
2023-12-18 11:36
array.html
32.76
KB
-rw-r--r--
2023-12-18 11:36
ast.html
38.67
KB
-rw-r--r--
2023-12-18 11:36
asynchat.html
31.78
KB
-rw-r--r--
2023-12-18 11:36
asyncio-dev.html
50.65
KB
-rw-r--r--
2023-12-18 11:36
asyncio-eventloop.html
108.61
KB
-rw-r--r--
2023-12-18 11:36
asyncio-eventloops.html
32.25
KB
-rw-r--r--
2023-12-18 11:36
asyncio-protocol.html
85.38
KB
-rw-r--r--
2023-12-18 11:36
asyncio-queue.html
23.4
KB
-rw-r--r--
2023-12-18 11:36
asyncio-stream.html
59.58
KB
-rw-r--r--
2023-12-18 11:36
asyncio-subprocess.html
56.66
KB
-rw-r--r--
2023-12-18 11:36
asyncio-sync.html
34.84
KB
-rw-r--r--
2023-12-18 11:36
asyncio-task.html
82
KB
-rw-r--r--
2023-12-18 11:36
asyncio.html
27.37
KB
-rw-r--r--
2023-12-18 11:36
asyncore.html
41.71
KB
-rw-r--r--
2023-12-18 11:36
atexit.html
18
KB
-rw-r--r--
2023-12-18 11:36
audioop.html
34.61
KB
-rw-r--r--
2023-12-18 11:36
base64.html
35.6
KB
-rw-r--r--
2023-12-18 11:36
bdb.html
42.41
KB
-rw-r--r--
2023-12-18 11:36
binary.html
12.42
KB
-rw-r--r--
2023-12-18 11:36
binascii.html
24.17
KB
-rw-r--r--
2023-12-18 11:36
binhex.html
11.4
KB
-rw-r--r--
2023-12-18 11:36
bisect.html
25
KB
-rw-r--r--
2023-12-18 11:36
builtins.html
11.33
KB
-rw-r--r--
2023-12-18 11:36
bz2.html
32.58
KB
-rw-r--r--
2023-12-18 11:36
calendar.html
38.61
KB
-rw-r--r--
2023-12-18 11:36
cgi.html
54.57
KB
-rw-r--r--
2023-12-18 11:36
cgitb.html
12.47
KB
-rw-r--r--
2023-12-18 11:36
chunk.html
16.48
KB
-rw-r--r--
2023-12-18 11:36
cmath.html
33.37
KB
-rw-r--r--
2023-12-18 11:36
cmd.html
42.78
KB
-rw-r--r--
2023-12-18 11:36
code.html
27.23
KB
-rw-r--r--
2023-12-18 11:36
codecs.html
130.93
KB
-rw-r--r--
2023-12-18 11:36
codeop.html
13.97
KB
-rw-r--r--
2023-12-18 11:36
collections.abc.html
59.48
KB
-rw-r--r--
2023-12-18 11:36
collections.html
151.31
KB
-rw-r--r--
2023-12-18 11:36
colorsys.html
12.33
KB
-rw-r--r--
2023-12-18 11:36
compileall.html
27.6
KB
-rw-r--r--
2023-12-18 11:36
concurrency.html
20.71
KB
-rw-r--r--
2023-12-18 11:36
concurrent.futures.html
59.24
KB
-rw-r--r--
2023-12-18 11:36
concurrent.html
7.77
KB
-rw-r--r--
2023-12-18 11:36
configparser.html
137.75
KB
-rw-r--r--
2023-12-18 11:36
constants.html
17.09
KB
-rw-r--r--
2023-12-18 11:36
contextlib.html
86.72
KB
-rw-r--r--
2023-12-18 11:36
copy.html
13.52
KB
-rw-r--r--
2023-12-18 11:36
copyreg.html
14.38
KB
-rw-r--r--
2023-12-18 11:36
crypt.html
19.85
KB
-rw-r--r--
2023-12-18 11:36
crypto.html
10.66
KB
-rw-r--r--
2023-12-18 11:36
csv.html
67.42
KB
-rw-r--r--
2023-12-18 11:36
ctypes.html
258.33
KB
-rw-r--r--
2023-12-18 11:36
curses.ascii.html
24.61
KB
-rw-r--r--
2023-12-18 11:36
curses.html
171.44
KB
-rw-r--r--
2023-12-18 11:36
curses.panel.html
16.31
KB
-rw-r--r--
2023-12-18 11:36
custominterp.html
8.53
KB
-rw-r--r--
2023-12-18 11:36
datatypes.html
23.39
KB
-rw-r--r--
2023-12-18 11:36
datetime.html
299.25
KB
-rw-r--r--
2023-12-18 11:36
dbm.html
42.11
KB
-rw-r--r--
2023-12-18 11:36
debug.html
13.66
KB
-rw-r--r--
2023-12-18 11:36
decimal.html
228.01
KB
-rw-r--r--
2023-12-18 11:36
development.html
24.53
KB
-rw-r--r--
2023-12-18 11:36
difflib.html
93.9
KB
-rw-r--r--
2023-12-18 11:36
dis.html
103.7
KB
-rw-r--r--
2023-12-18 11:36
distribution.html
10.26
KB
-rw-r--r--
2023-12-18 11:36
distutils.html
10.63
KB
-rw-r--r--
2023-12-18 11:36
doctest.html
175.54
KB
-rw-r--r--
2023-12-18 11:36
dummy_threading.html
9.1
KB
-rw-r--r--
2023-12-18 11:36
email.charset.html
25.81
KB
-rw-r--r--
2023-12-18 11:36
email.compat32-message.html
84.13
KB
-rw-r--r--
2023-12-18 11:36
email.contentmanager.html
29.32
KB
-rw-r--r--
2023-12-18 11:36
email.encoders.html
13.92
KB
-rw-r--r--
2023-12-18 11:36
email.errors.html
19.24
KB
-rw-r--r--
2023-12-18 11:36
email.examples.html
56.52
KB
-rw-r--r--
2023-12-18 11:36
email.generator.html
40.82
KB
-rw-r--r--
2023-12-18 11:36
email.header.html
30.49
KB
-rw-r--r--
2023-12-18 11:36
email.headerregistry.html
56.32
KB
-rw-r--r--
2023-12-18 11:36
email.html
27.09
KB
-rw-r--r--
2023-12-18 11:36
email.iterators.html
13.21
KB
-rw-r--r--
2023-12-18 11:36
email.message.html
85.17
KB
-rw-r--r--
2023-12-18 11:36
email.mime.html
35.24
KB
-rw-r--r--
2023-12-18 11:36
email.parser.html
46.32
KB
-rw-r--r--
2023-12-18 11:36
email.policy.html
73.48
KB
-rw-r--r--
2023-12-18 11:36
email.util.html
33.06
KB
-rw-r--r--
2023-12-18 11:36
ensurepip.html
18.26
KB
-rw-r--r--
2023-12-18 11:36
enum.html
130.81
KB
-rw-r--r--
2023-12-18 11:36
errno.html
40.36
KB
-rw-r--r--
2023-12-18 11:36
exceptions.html
83.16
KB
-rw-r--r--
2023-12-18 11:36
faulthandler.html
22.85
KB
-rw-r--r--
2023-12-18 11:36
fcntl.html
26.68
KB
-rw-r--r--
2023-12-18 11:36
filecmp.html
24.45
KB
-rw-r--r--
2023-12-18 11:36
fileformats.html
10.87
KB
-rw-r--r--
2023-12-18 11:36
fileinput.html
29.33
KB
-rw-r--r--
2023-12-18 11:36
filesys.html
13.1
KB
-rw-r--r--
2023-12-18 11:36
fnmatch.html
16.59
KB
-rw-r--r--
2023-12-18 11:36
formatter.html
36.78
KB
-rw-r--r--
2023-12-18 11:36
fpectl.html
17.13
KB
-rw-r--r--
2023-12-18 11:36
fractions.html
29.22
KB
-rw-r--r--
2023-12-18 11:36
frameworks.html
13.16
KB
-rw-r--r--
2023-12-18 11:36
ftplib.html
53.15
KB
-rw-r--r--
2023-12-18 11:36
functional.html
8.79
KB
-rw-r--r--
2023-12-18 11:36
functions.html
196.76
KB
-rw-r--r--
2023-12-18 11:36
functools.html
63.43
KB
-rw-r--r--
2023-12-18 11:36
gc.html
28.83
KB
-rw-r--r--
2023-12-18 11:36
getopt.html
24.76
KB
-rw-r--r--
2023-12-18 11:36
getpass.html
11.78
KB
-rw-r--r--
2023-12-18 11:36
gettext.html
74.84
KB
-rw-r--r--
2023-12-18 11:36
glob.html
18
KB
-rw-r--r--
2023-12-18 11:36
grp.html
12.09
KB
-rw-r--r--
2023-12-18 11:36
gzip.html
31.9
KB
-rw-r--r--
2023-12-18 11:36
hashlib.html
77.69
KB
-rw-r--r--
2023-12-18 11:36
heapq.html
34.7
KB
-rw-r--r--
2023-12-18 11:36
hmac.html
17.41
KB
-rw-r--r--
2023-12-18 11:36
html.entities.html
11.09
KB
-rw-r--r--
2023-12-18 11:36
html.html
10.85
KB
-rw-r--r--
2023-12-18 11:36
html.parser.html
40.86
KB
-rw-r--r--
2023-12-18 11:36
http.client.html
63.72
KB
-rw-r--r--
2023-12-18 11:36
http.cookiejar.html
93.94
KB
-rw-r--r--
2023-12-18 11:36
http.cookies.html
38.41
KB
-rw-r--r--
2023-12-18 11:36
http.html
36.72
KB
-rw-r--r--
2023-12-18 11:36
http.server.html
56.83
KB
-rw-r--r--
2023-12-18 11:36
i18n.html
10.22
KB
-rw-r--r--
2023-12-18 11:36
idle.html
47.28
KB
-rw-r--r--
2023-12-18 11:36
imaplib.html
65.76
KB
-rw-r--r--
2023-12-18 11:36
imghdr.html
13.14
KB
-rw-r--r--
2023-12-18 11:36
imp.html
47.02
KB
-rw-r--r--
2023-12-18 11:36
importlib.html
169.05
KB
-rw-r--r--
2023-12-18 11:36
index.html
66.18
KB
-rw-r--r--
2023-12-18 11:36
inspect.html
127.3
KB
-rw-r--r--
2023-12-18 11:36
internet.html
30.36
KB
-rw-r--r--
2023-12-18 11:36
intro.html
9.67
KB
-rw-r--r--
2023-12-18 11:36
io.html
119.81
KB
-rw-r--r--
2023-12-18 11:36
ipaddress.html
103.39
KB
-rw-r--r--
2023-12-18 11:36
ipc.html
32.95
KB
-rw-r--r--
2023-12-18 11:36
itertools.html
129.71
KB
-rw-r--r--
2023-12-18 11:36
json.html
79.18
KB
-rw-r--r--
2023-12-18 11:36
keyword.html
8.71
KB
-rw-r--r--
2023-12-18 11:36
language.html
13.33
KB
-rw-r--r--
2023-12-18 11:36
linecache.html
13.18
KB
-rw-r--r--
2023-12-18 11:36
locale.html
60.1
KB
-rw-r--r--
2023-12-18 11:36
logging.config.html
83.49
KB
-rw-r--r--
2023-12-18 11:36
logging.handlers.html
109.76
KB
-rw-r--r--
2023-12-18 11:36
logging.html
131.69
KB
-rw-r--r--
2023-12-18 11:36
lzma.html
55.16
KB
-rw-r--r--
2023-12-18 11:36
macpath.html
9.04
KB
-rw-r--r--
2023-12-18 11:36
mailbox.html
153.63
KB
-rw-r--r--
2023-12-18 11:36
mailcap.html
14.33
KB
-rw-r--r--
2023-12-18 11:36
markup.html
18.9
KB
-rw-r--r--
2023-12-18 11:36
marshal.html
17.89
KB
-rw-r--r--
2023-12-18 11:36
math.html
52.4
KB
-rw-r--r--
2023-12-18 11:36
mimetypes.html
30.67
KB
-rw-r--r--
2023-12-18 11:36
misc.html
7.93
KB
-rw-r--r--
2023-12-18 11:36
mm.html
9.79
KB
-rw-r--r--
2023-12-18 11:36
mmap.html
33.49
KB
-rw-r--r--
2023-12-18 11:36
modulefinder.html
18.12
KB
-rw-r--r--
2023-12-18 11:36
modules.html
10.66
KB
-rw-r--r--
2023-12-18 11:36
msilib.html
55.86
KB
-rw-r--r--
2023-12-18 11:36
msvcrt.html
21.47
KB
-rw-r--r--
2023-12-18 11:36
multiprocessing.html
356.92
KB
-rw-r--r--
2023-12-18 11:36
netdata.html
17.06
KB
-rw-r--r--
2023-12-18 11:36
netrc.html
14.23
KB
-rw-r--r--
2023-12-18 11:36
nis.html
11.39
KB
-rw-r--r--
2023-12-18 11:36
nntplib.html
67.97
KB
-rw-r--r--
2023-12-18 11:36
numbers.html
40.46
KB
-rw-r--r--
2023-12-18 11:36
numeric.html
15.17
KB
-rw-r--r--
2023-12-18 11:36
operator.html
79.55
KB
-rw-r--r--
2023-12-18 11:36
optparse.html
244.08
KB
-rw-r--r--
2023-12-18 11:36
os.html
388.71
KB
-rw-r--r--
2023-12-18 11:36
os.path.html
52.56
KB
-rw-r--r--
2023-12-18 11:36
ossaudiodev.html
46.82
KB
-rw-r--r--
2023-12-18 11:36
othergui.html
10.02
KB
-rw-r--r--
2023-12-18 11:36
parser.html
41.41
KB
-rw-r--r--
2023-12-18 11:36
pathlib.html
113.99
KB
-rw-r--r--
2023-12-18 11:36
pdb.html
51.43
KB
-rw-r--r--
2023-12-18 11:36
persistence.html
14.92
KB
-rw-r--r--
2023-12-18 11:36
pickle.html
112.36
KB
-rw-r--r--
2023-12-18 11:36
pickletools.html
16.69
KB
-rw-r--r--
2023-12-18 11:36
pipes.html
15.62
KB
-rw-r--r--
2023-12-18 11:36
pkgutil.html
31.13
KB
-rw-r--r--
2023-12-18 11:36
platform.html
32.94
KB
-rw-r--r--
2023-12-18 11:36
plistlib.html
28.6
KB
-rw-r--r--
2023-12-18 11:36
poplib.html
30.21
KB
-rw-r--r--
2023-12-18 11:36
posix.html
17.2
KB
-rw-r--r--
2023-12-18 11:36
pprint.html
40.99
KB
-rw-r--r--
2023-12-18 11:36
profile.html
70.16
KB
-rw-r--r--
2023-12-18 11:36
pty.html
17.18
KB
-rw-r--r--
2023-12-18 11:36
pwd.html
12.79
KB
-rw-r--r--
2023-12-18 11:36
py_compile.html
15.14
KB
-rw-r--r--
2023-12-18 11:36
pyclbr.html
16.13
KB
-rw-r--r--
2023-12-18 11:36
pydoc.html
15.62
KB
-rw-r--r--
2023-12-18 11:36
pyexpat.html
86.85
KB
-rw-r--r--
2023-12-18 11:36
python.html
16.73
KB
-rw-r--r--
2023-12-18 11:36
queue.html
27.54
KB
-rw-r--r--
2023-12-18 11:36
quopri.html
13.53
KB
-rw-r--r--
2023-12-18 11:36
random.html
59.22
KB
-rw-r--r--
2023-12-18 11:36
re.html
186.7
KB
-rw-r--r--
2023-12-18 11:36
readline.html
41.15
KB
-rw-r--r--
2023-12-18 11:36
reprlib.html
24.38
KB
-rw-r--r--
2023-12-18 11:36
resource.html
35.7
KB
-rw-r--r--
2023-12-18 11:36
rlcompleter.html
14.05
KB
-rw-r--r--
2023-12-18 11:36
runpy.html
25.98
KB
-rw-r--r--
2023-12-18 11:36
sched.html
19.56
KB
-rw-r--r--
2023-12-18 11:36
secrets.html
24.15
KB
-rw-r--r--
2023-12-18 11:36
select.html
61.35
KB
-rw-r--r--
2023-12-18 11:36
selectors.html
35
KB
-rw-r--r--
2023-12-18 11:36
shelve.html
28.1
KB
-rw-r--r--
2023-12-18 11:36
shlex.html
47.83
KB
-rw-r--r--
2023-12-18 11:36
shutil.html
72.47
KB
-rw-r--r--
2023-12-18 11:36
signal.html
53.77
KB
-rw-r--r--
2023-12-18 11:36
site.html
31.49
KB
-rw-r--r--
2023-12-18 11:36
smtpd.html
35.05
KB
-rw-r--r--
2023-12-18 11:36
smtplib.html
66.83
KB
-rw-r--r--
2023-12-18 11:36
sndhdr.html
12.15
KB
-rw-r--r--
2023-12-18 11:36
socket.html
191.48
KB
-rw-r--r--
2023-12-18 11:36
socketserver.html
80
KB
-rw-r--r--
2023-12-18 11:36
spwd.html
12.04
KB
-rw-r--r--
2023-12-18 11:36
sqlite3.html
158.08
KB
-rw-r--r--
2023-12-18 11:36
ssl.html
260.08
KB
-rw-r--r--
2023-12-18 11:36
stat.html
43.67
KB
-rw-r--r--
2023-12-18 11:36
statistics.html
48.88
KB
-rw-r--r--
2023-12-18 11:36
stdtypes.html
454.74
KB
-rw-r--r--
2023-12-18 11:36
string.html
93.03
KB
-rw-r--r--
2023-12-18 11:36
stringprep.html
18.22
KB
-rw-r--r--
2023-12-18 11:36
struct.html
49.9
KB
-rw-r--r--
2023-12-18 11:36
subprocess.html
138.6
KB
-rw-r--r--
2023-12-18 11:36
sunau.html
31.01
KB
-rw-r--r--
2023-12-18 11:36
superseded.html
13.46
KB
-rw-r--r--
2023-12-18 11:36
symbol.html
8.64
KB
-rw-r--r--
2023-12-18 11:36
symtable.html
25.5
KB
-rw-r--r--
2023-12-18 11:36
sys.html
138.35
KB
-rw-r--r--
2023-12-18 11:36
sysconfig.html
29.55
KB
-rw-r--r--
2023-12-18 11:36
syslog.html
20.53
KB
-rw-r--r--
2023-12-18 11:36
tabnanny.html
11.98
KB
-rw-r--r--
2023-12-18 11:36
tarfile.html
94.49
KB
-rw-r--r--
2023-12-18 11:36
telnetlib.html
29.7
KB
-rw-r--r--
2023-12-18 11:36
tempfile.html
40.42
KB
-rw-r--r--
2023-12-18 11:36
termios.html
17.75
KB
-rw-r--r--
2023-12-18 11:36
test.html
76.71
KB
-rw-r--r--
2023-12-18 11:36
text.html
13.46
KB
-rw-r--r--
2023-12-18 11:36
textwrap.html
37.11
KB
-rw-r--r--
2023-12-18 11:36
threading.html
101.04
KB
-rw-r--r--
2023-12-18 11:36
time.html
77.76
KB
-rw-r--r--
2023-12-18 11:36
timeit.html
44.19
KB
-rw-r--r--
2023-12-18 11:36
tk.html
22.75
KB
-rw-r--r--
2023-12-18 11:36
tkinter.html
80.99
KB
-rw-r--r--
2023-12-18 11:36
tkinter.scrolledtext.html
9.72
KB
-rw-r--r--
2023-12-18 11:36
tkinter.tix.html
50.64
KB
-rw-r--r--
2023-12-18 11:36
tkinter.ttk.html
108.08
KB
-rw-r--r--
2023-12-18 11:36
token.html
22.13
KB
-rw-r--r--
2023-12-18 11:36
tokenize.html
31.4
KB
-rw-r--r--
2023-12-18 11:36
trace.html
28.46
KB
-rw-r--r--
2023-12-18 11:36
traceback.html
56.24
KB
-rw-r--r--
2023-12-18 11:36
tracemalloc.html
98.77
KB
-rw-r--r--
2023-12-18 11:36
tty.html
10.29
KB
-rw-r--r--
2023-12-18 11:36
turtle.html
244.5
KB
-rw-r--r--
2023-12-18 11:36
types.html
36.19
KB
-rw-r--r--
2023-12-18 11:36
typing.html
135.91
KB
-rw-r--r--
2023-12-18 11:36
undoc.html
8.97
KB
-rw-r--r--
2023-12-18 11:36
unicodedata.html
20.61
KB
-rw-r--r--
2023-12-18 11:36
unittest.html
244.81
KB
-rw-r--r--
2023-12-18 11:36
unittest.mock-examples.html
164.2
KB
-rw-r--r--
2023-12-18 11:36
unittest.mock.html
293.06
KB
-rw-r--r--
2023-12-18 11:36
unix.html
11.5
KB
-rw-r--r--
2023-12-18 11:36
urllib.error.html
14.13
KB
-rw-r--r--
2023-12-18 11:36
urllib.html
9.34
KB
-rw-r--r--
2023-12-18 11:36
urllib.parse.html
74.54
KB
-rw-r--r--
2023-12-18 11:36
urllib.request.html
173.05
KB
-rw-r--r--
2023-12-18 11:36
urllib.robotparser.html
16.75
KB
-rw-r--r--
2023-12-18 11:36
uu.html
11.92
KB
-rw-r--r--
2023-12-18 11:36
uuid.html
31.21
KB
-rw-r--r--
2023-12-18 11:36
venv.html
72.18
KB
-rw-r--r--
2023-12-18 11:36
warnings.html
49.14
KB
-rw-r--r--
2023-12-18 11:36
wave.html
29.17
KB
-rw-r--r--
2023-12-18 11:36
weakref.html
63.76
KB
-rw-r--r--
2023-12-18 11:36
webbrowser.html
26.27
KB
-rw-r--r--
2023-12-18 11:36
windows.html
10.38
KB
-rw-r--r--
2023-12-18 11:36
winreg.html
65.17
KB
-rw-r--r--
2023-12-18 11:36
winsound.html
20.77
KB
-rw-r--r--
2023-12-18 11:36
wsgiref.html
92.28
KB
-rw-r--r--
2023-12-18 11:36
xdrlib.html
32.96
KB
-rw-r--r--
2023-12-18 11:36
xml.dom.html
95.28
KB
-rw-r--r--
2023-12-18 11:36
xml.dom.minidom.html
40.51
KB
-rw-r--r--
2023-12-18 11:36
xml.dom.pulldom.html
23.65
KB
-rw-r--r--
2023-12-18 11:36
xml.etree.elementtree.html
132.32
KB
-rw-r--r--
2023-12-18 11:36
xml.html
18.81
KB
-rw-r--r--
2023-12-18 11:36
xml.sax.handler.html
41.66
KB
-rw-r--r--
2023-12-18 11:36
xml.sax.html
24.92
KB
-rw-r--r--
2023-12-18 11:36
xml.sax.reader.html
44.79
KB
-rw-r--r--
2023-12-18 11:36
xml.sax.utils.html
16.53
KB
-rw-r--r--
2023-12-18 11:36
xmlrpc.client.html
70.26
KB
-rw-r--r--
2023-12-18 11:36
xmlrpc.html
8.33
KB
-rw-r--r--
2023-12-18 11:36
xmlrpc.server.html
48.04
KB
-rw-r--r--
2023-12-18 11:36
zipapp.html
44.05
KB
-rw-r--r--
2023-12-18 11:36
zipfile.html
78.16
KB
-rw-r--r--
2023-12-18 11:36
zipimport.html
22.51
KB
-rw-r--r--
2023-12-18 11:36
zlib.html
33.75
KB
-rw-r--r--
2023-12-18 11:36
Save
Rename
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>11.1. pathlib — Object-oriented filesystem paths — Python 3.6.7 documentation</title> <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 3.6.7 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="11.2. os.path — Common pathname manipulations" href="os.path.html" /> <link rel="prev" title="11. File and Directory Access" href="filesys.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="https://docs.python.org/3/library/pathlib.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head><body> <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="11.2. os.path — Common pathname manipulations" accesskey="N">next</a> |</li> <li class="right" > <a href="filesys.html" title="11. File and Directory Access" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.6.7 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">11. File and Directory Access</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="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> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-pathlib"> <span id="pathlib-object-oriented-filesystem-paths"></span><h1>11.1. <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">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.6/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>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>.</li> <li>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.</li> </ol> <div class="admonition seealso"> <p class="first admonition-title">See also</p> <p class="last"><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="first admonition-title">See also</p> <p class="last">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> <div class="section" id="basic-use"> <h2>11.1.1. 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="k">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> </div> <div class="section" id="pure-paths"> <span id="id1"></span><h2>11.1.2. 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="class"> <dt id="pathlib.PurePath"> <em class="property">class </em><code class="descclassname">pathlib.</code><code class="descname">PurePath</code><span class="sig-paren">(</span><em>*pathsegments</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>When several absolute paths are given, the last is taken as an anchor (mimicking <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>’s behaviour):</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>However, in a Windows path, changing the local root doesn’t discard the previous drive setting:</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>) are not, since this would change the meaning of a path in the face of symbolic links:</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> </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 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="class"> <dt id="pathlib.PurePosixPath"> <em class="property">class </em><code class="descclassname">pathlib.</code><code class="descname">PurePosixPath</code><span class="sig-paren">(</span><em>*pathsegments</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="class"> <dt id="pathlib.PureWindowsPath"> <em class="property">class </em><code class="descclassname">pathlib.</code><code class="descname">PureWindowsPath</code><span class="sig-paren">(</span><em>*pathsegments</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:</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> </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> <div class="section" id="general-properties"> <h3>11.1.2.1. General properties<a class="headerlink" href="#general-properties" title="Permalink to this headline">¶</a></h3> <p>Paths are immutable and hashable. 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> </div> <div class="section" id="operators"> <h3>11.1.2.2. Operators<a class="headerlink" href="#operators" title="Permalink to this headline">¶</a></h3> <p>The slash operator helps create child paths, similarly to <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">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> </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="first admonition-title">Note</p> <p class="last">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> </div> <div class="section" id="accessing-individual-parts"> <h3>11.1.2.3. 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="data"> <dt id="pathlib.PurePath.parts"> <code class="descclassname">PurePath.</code><code class="descname">parts</code><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> </div> <div class="section" id="methods-and-properties"> <h3>11.1.2.4. 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="data"> <dt id="pathlib.PurePath.drive"> <code class="descclassname">PurePath.</code><code class="descname">drive</code><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="data"> <dt id="pathlib.PurePath.root"> <code class="descclassname">PurePath.</code><code class="descname">root</code><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> </dd></dl> <dl class="data"> <dt id="pathlib.PurePath.anchor"> <code class="descclassname">PurePath.</code><code class="descname">anchor</code><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="data"> <dt id="pathlib.PurePath.parents"> <code class="descclassname">PurePath.</code><code class="descname">parents</code><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> </dd></dl> <dl class="data"> <dt id="pathlib.PurePath.parent"> <code class="descclassname">PurePath.</code><code class="descname">parent</code><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="first 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 class="last">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="data"> <dt id="pathlib.PurePath.name"> <code class="descclassname">PurePath.</code><code class="descname">name</code><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="data"> <dt id="pathlib.PurePath.suffix"> <code class="descclassname">PurePath.</code><code class="descname">suffix</code><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="data"> <dt id="pathlib.PurePath.suffixes"> <code class="descclassname">PurePath.</code><code class="descname">suffixes</code><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="data"> <dt id="pathlib.PurePath.stem"> <code class="descclassname">PurePath.</code><code class="descname">stem</code><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="method"> <dt id="pathlib.PurePath.as_posix"> <code class="descclassname">PurePath.</code><code class="descname">as_posix</code><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="method"> <dt id="pathlib.PurePath.as_uri"> <code class="descclassname">PurePath.</code><code class="descname">as_uri</code><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="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">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="method"> <dt id="pathlib.PurePath.is_absolute"> <code class="descclassname">PurePath.</code><code class="descname">is_absolute</code><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="method"> <dt id="pathlib.PurePath.is_reserved"> <code class="descclassname">PurePath.</code><code class="descname">is_reserved</code><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="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">'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="method"> <dt id="pathlib.PurePath.joinpath"> <code class="descclassname">PurePath.</code><code class="descname">joinpath</code><span class="sig-paren">(</span><em>*other</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="method"> <dt id="pathlib.PurePath.match"> <code class="descclassname">PurePath.</code><code class="descname">match</code><span class="sig-paren">(</span><em>pattern</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 is observed:</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">'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="method"> <dt id="pathlib.PurePath.relative_to"> <code class="descclassname">PurePath.</code><code class="descname">relative_to</code><span class="sig-paren">(</span><em>*other</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' does not start with '/usr'</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="pathlib.PurePath.with_name"> <code class="descclassname">PurePath.</code><code class="descname">with_name</code><span class="sig-paren">(</span><em>name</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="method"> <dt id="pathlib.PurePath.with_suffix"> <code class="descclassname">PurePath.</code><code class="descname">with_suffix</code><span class="sig-paren">(</span><em>suffix</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> </div> </div> <div class="section" id="concrete-paths"> <span id="id2"></span><h2>11.1.3. 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="class"> <dt id="pathlib.Path"> <em class="property">class </em><code class="descclassname">pathlib.</code><code class="descname">Path</code><span class="sig-paren">(</span><em>*pathsegments</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="class"> <dt id="pathlib.PosixPath"> <em class="property">class </em><code class="descclassname">pathlib.</code><code class="descname">PosixPath</code><span class="sig-paren">(</span><em>*pathsegments</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="class"> <dt id="pathlib.WindowsPath"> <em class="property">class </em><code class="descclassname">pathlib.</code><code class="descname">WindowsPath</code><span class="sig-paren">(</span><em>*pathsegments</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> <div class="section" id="methods"> <h3>11.1.3.1. 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> <dl class="classmethod"> <dt id="pathlib.Path.cwd"> <em class="property">classmethod </em><code class="descclassname">Path.</code><code class="descname">cwd</code><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="classmethod"> <dt id="pathlib.Path.home"> <em class="property">classmethod </em><code class="descclassname">Path.</code><code class="descname">home</code><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):</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">New in version 3.5.</span></p> </div> </dd></dl> <dl class="method"> <dt id="pathlib.Path.stat"> <code class="descclassname">Path.</code><code class="descname">stat</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pathlib.Path.stat" title="Permalink to this definition">¶</a></dt> <dd><p>Return information about this path (similarly to <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> <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> </dd></dl> <dl class="method"> <dt id="pathlib.Path.chmod"> <code class="descclassname">Path.</code><code class="descname">chmod</code><span class="sig-paren">(</span><em>mode</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> <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> </dd></dl> <dl class="method"> <dt id="pathlib.Path.exists"> <code class="descclassname">Path.</code><code class="descname">exists</code><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="first admonition-title">Note</p> <p class="last">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="method"> <dt id="pathlib.Path.expanduser"> <code class="descclassname">Path.</code><code class="descname">expanduser</code><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>:</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">New in version 3.5.</span></p> </div> </dd></dl> <dl class="method"> <dt id="pathlib.Path.glob"> <code class="descclassname">Path.</code><code class="descname">glob</code><span class="sig-paren">(</span><em>pattern</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 <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>The “<code class="docutils literal notranslate"><span class="pre">**</span></code>” pattern 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="first admonition-title">Note</p> <p class="last">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> </dd></dl> <dl class="method"> <dt id="pathlib.Path.group"> <code class="descclassname">Path.</code><code class="descname">group</code><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="method"> <dt id="pathlib.Path.is_dir"> <code class="descclassname">Path.</code><code class="descname">is_dir</code><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="method"> <dt id="pathlib.Path.is_file"> <code class="descclassname">Path.</code><code class="descname">is_file</code><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="method"> <dt id="pathlib.Path.is_symlink"> <code class="descclassname">Path.</code><code class="descname">is_symlink</code><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="method"> <dt id="pathlib.Path.is_socket"> <code class="descclassname">Path.</code><code class="descname">is_socket</code><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="method"> <dt id="pathlib.Path.is_fifo"> <code class="descclassname">Path.</code><code class="descname">is_fifo</code><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="method"> <dt id="pathlib.Path.is_block_device"> <code class="descclassname">Path.</code><code class="descname">is_block_device</code><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="method"> <dt id="pathlib.Path.is_char_device"> <code class="descclassname">Path.</code><code class="descname">is_char_device</code><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="method"> <dt id="pathlib.Path.iterdir"> <code class="descclassname">Path.</code><code class="descname">iterdir</code><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> </dd></dl> <dl class="method"> <dt id="pathlib.Path.lchmod"> <code class="descclassname">Path.</code><code class="descname">lchmod</code><span class="sig-paren">(</span><em>mode</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="method"> <dt id="pathlib.Path.lstat"> <code class="descclassname">Path.</code><code class="descname">lstat</code><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="method"> <dt id="pathlib.Path.mkdir"> <code class="descclassname">Path.</code><code class="descname">mkdir</code><span class="sig-paren">(</span><em>mode=0o777</em>, <em>parents=False</em>, <em>exist_ok=False</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 in version 3.5: </span>The <em>exist_ok</em> parameter was added.</p> </div> </dd></dl> <dl class="method"> <dt id="pathlib.Path.open"> <code class="descclassname">Path.</code><code class="descname">open</code><span class="sig-paren">(</span><em>mode='r'</em>, <em>buffering=-1</em>, <em>encoding=None</em>, <em>errors=None</em>, <em>newline=None</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="method"> <dt id="pathlib.Path.owner"> <code class="descclassname">Path.</code><code class="descname">owner</code><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="method"> <dt id="pathlib.Path.read_bytes"> <code class="descclassname">Path.</code><code class="descname">read_bytes</code><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">New in version 3.5.</span></p> </div> </dd></dl> <dl class="method"> <dt id="pathlib.Path.read_text"> <code class="descclassname">Path.</code><code class="descname">read_text</code><span class="sig-paren">(</span><em>encoding=None</em>, <em>errors=None</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">New in version 3.5.</span></p> </div> </dd></dl> <dl class="method"> <dt id="pathlib.Path.rename"> <code class="descclassname">Path.</code><code class="descname">rename</code><span class="sig-paren">(</span><em>target</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>. On Unix, if <em>target</em> exists and is a file, it will be replaced silently if the user has permission. <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="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> </dd></dl> <dl class="method"> <dt id="pathlib.Path.replace"> <code class="descclassname">Path.</code><code class="descname">replace</code><span class="sig-paren">(</span><em>target</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>. If <em>target</em> points to an existing file or directory, it will be unconditionally replaced.</p> </dd></dl> <dl class="method"> <dt id="pathlib.Path.resolve"> <code class="descclassname">Path.</code><code class="descname">resolve</code><span class="sig-paren">(</span><em>strict=False</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">New in version 3.6: </span>The <em>strict</em> argument.</p> </div> </dd></dl> <dl class="method"> <dt id="pathlib.Path.rglob"> <code class="descclassname">Path.</code><code class="descname">rglob</code><span class="sig-paren">(</span><em>pattern</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-meth 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 <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> </dd></dl> <dl class="method"> <dt id="pathlib.Path.rmdir"> <code class="descclassname">Path.</code><code class="descname">rmdir</code><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="method"> <dt id="pathlib.Path.samefile"> <code class="descclassname">Path.</code><code class="descname">samefile</code><span class="sig-paren">(</span><em>other_path</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">New in version 3.5.</span></p> </div> </dd></dl> <dl class="method"> <dt id="pathlib.Path.symlink_to"> <code class="descclassname">Path.</code><code class="descname">symlink_to</code><span class="sig-paren">(</span><em>target</em>, <em>target_is_directory=False</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="first admonition-title">Note</p> <p class="last">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="method"> <dt id="pathlib.Path.touch"> <code class="descclassname">Path.</code><code class="descname">touch</code><span class="sig-paren">(</span><em>mode=0o666</em>, <em>exist_ok=True</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="method"> <dt id="pathlib.Path.unlink"> <code class="descclassname">Path.</code><code class="descname">unlink</code><span class="sig-paren">(</span><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> </dd></dl> <dl class="method"> <dt id="pathlib.Path.write_bytes"> <code class="descclassname">Path.</code><code class="descname">write_bytes</code><span class="sig-paren">(</span><em>data</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">New in version 3.5.</span></p> </div> </dd></dl> <dl class="method"> <dt id="pathlib.Path.write_text"> <code class="descclassname">Path.</code><code class="descname">write_text</code><span class="sig-paren">(</span><em>data</em>, <em>encoding=None</em>, <em>errors=None</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> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> </div> </div> </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="#">11.1. <code class="docutils literal notranslate"><span class="pre">pathlib</span></code> — Object-oriented filesystem paths</a><ul> <li><a class="reference internal" href="#basic-use">11.1.1. Basic use</a></li> <li><a class="reference internal" href="#pure-paths">11.1.2. Pure paths</a><ul> <li><a class="reference internal" href="#general-properties">11.1.2.1. General properties</a></li> <li><a class="reference internal" href="#operators">11.1.2.2. Operators</a></li> <li><a class="reference internal" href="#accessing-individual-parts">11.1.2.3. Accessing individual parts</a></li> <li><a class="reference internal" href="#methods-and-properties">11.1.2.4. Methods and properties</a></li> </ul> </li> <li><a class="reference internal" href="#concrete-paths">11.1.3. Concrete paths</a><ul> <li><a class="reference internal" href="#methods">11.1.3.1. Methods</a></li> </ul> </li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="filesys.html" title="previous chapter">11. File and Directory Access</a></p> <h4>Next topic</h4> <p class="topless"><a href="os.path.html" title="next chapter">11.2. <code class="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.6/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="11.2. os.path — Common pathname manipulations" >next</a> |</li> <li class="right" > <a href="filesys.html" title="11. File and Directory Access" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.6.7 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" >11. File and Directory Access</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="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> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 2001-2023, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Dec 18, 2023. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.6. </div> </body> </html>