blob: 36bb21c222ed2801f64b396855c927e2a8e60757 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`os.path` --- Common pathname manipulations
2================================================
3
4.. module:: os.path
5 :synopsis: Operations on pathnames.
6
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04007**Source code:** :source:`Lib/posixpath.py` (for POSIX),
8:source:`Lib/ntpath.py` (for Windows NT),
9and :source:`Lib/macpath.py` (for Macintosh)
10
Georg Brandl116aa622007-08-15 14:28:22 +000011.. index:: single: path; operations
12
Terry Jan Reedyfa089b92016-06-11 15:02:54 -040013--------------
14
Georg Brandl116aa622007-08-15 14:28:22 +000015This module implements some useful functions on pathnames. To read or
16write files see :func:`open`, and for accessing the filesystem see the
Martin v. Löwis651423c2008-10-07 07:03:04 +000017:mod:`os` module. The path parameters can be passed as either strings,
18or bytes. Applications are encouraged to represent file names as
19(Unicode) character strings. Unfortunately, some file names may not be
20representable as strings on Unix, so applications that need to support
21arbitrary file names on Unix should use bytes objects to represent
22path names. Vice versa, using bytes objects cannot represent all file
23names on Windows (in the standard ``mbcs`` encoding), hence Windows
24applications should use string objects to access all files.
Georg Brandl116aa622007-08-15 14:28:22 +000025
R David Murraya4e700c2013-01-06 16:13:10 -050026Unlike a unix shell, Python does not do any *automatic* path expansions.
27Functions such as :func:`expanduser` and :func:`expandvars` can be invoked
28explicitly when an application desires shell-like path expansion. (See also
29the :mod:`glob` module.)
30
Antoine Pitrou31119e42013-11-22 17:38:12 +010031
32.. seealso::
33 The :mod:`pathlib` module offers high-level path objects.
34
35
Georg Brandl76e55382008-10-08 16:34:57 +000036.. note::
37
38 All of these functions accept either only bytes or only string objects as
39 their parameters. The result is an object of the same type, if a path or
40 file name is returned.
41
Georg Brandl116aa622007-08-15 14:28:22 +000042
Benjamin Petersond23f8222009-04-05 19:13:16 +000043.. note::
44
45 Since different operating systems have different path name conventions, there
46 are several versions of this module in the standard library. The
47 :mod:`os.path` module is always the path module suitable for the operating
48 system Python is running on, and therefore usable for local paths. However,
49 you can also import and use the individual modules if you want to manipulate
50 a path that is *always* in one of the different formats. They all have the
51 same interface:
52
53 * :mod:`posixpath` for UNIX-style paths
54 * :mod:`ntpath` for Windows paths
55 * :mod:`macpath` for old-style MacOS paths
Benjamin Petersond23f8222009-04-05 19:13:16 +000056
57
Georg Brandl116aa622007-08-15 14:28:22 +000058.. function:: abspath(path)
59
60 Return a normalized absolutized version of the pathname *path*. On most
Chris Jerdonek0b502ff2012-11-25 20:38:01 -080061 platforms, this is equivalent to calling the function :func:`normpath` as
62 follows: ``normpath(join(os.getcwd(), path))``.
Georg Brandl116aa622007-08-15 14:28:22 +000063
Brett Cannon6fa7aad2016-09-06 15:55:02 -070064 .. versionchanged:: 3.6
65 Accepts a :term:`path-like object`.
66
Georg Brandl116aa622007-08-15 14:28:22 +000067
68.. function:: basename(path)
69
Chris Jerdonek0b502ff2012-11-25 20:38:01 -080070 Return the base name of pathname *path*. This is the second element of the
71 pair returned by passing *path* to the function :func:`split`. Note that
72 the result of this function is different
Georg Brandl116aa622007-08-15 14:28:22 +000073 from the Unix :program:`basename` program; where :program:`basename` for
74 ``'/foo/bar/'`` returns ``'bar'``, the :func:`basename` function returns an
75 empty string (``''``).
76
Brett Cannon6fa7aad2016-09-06 15:55:02 -070077 .. versionchanged:: 3.6
78 Accepts a :term:`path-like object`.
79
Georg Brandl116aa622007-08-15 14:28:22 +000080
Serhiy Storchaka38220932015-03-31 15:31:53 +030081.. function:: commonpath(paths)
82
83 Return the longest common sub-path of each pathname in the sequence
84 *paths*. Raise ValueError if *paths* contains both absolute and relative
85 pathnames, or if *paths* is empty. Unlike :func:`commonprefix`, this
86 returns a valid path.
87
88 Availability: Unix, Windows
89
90 .. versionadded:: 3.5
91
Brett Cannon6fa7aad2016-09-06 15:55:02 -070092 .. versionchanged:: 3.6
93 Accepts a sequence of :term:`path-like objects <path-like object>`.
94
Serhiy Storchaka38220932015-03-31 15:31:53 +030095
Georg Brandl116aa622007-08-15 14:28:22 +000096.. function:: commonprefix(list)
97
Serhiy Storchaka38220932015-03-31 15:31:53 +030098 Return the longest path prefix (taken character-by-character) that is a
99 prefix of all paths in *list*. If *list* is empty, return the empty string
Yury Selivanov80ac11f2015-08-17 23:43:43 -0400100 (``''``).
101
102 .. note::
103
104 This function may return invalid paths because it works a
105 character at a time. To obtain a valid path, see
106 :func:`commonpath`.
107
108 ::
109
Yury Selivanovde115612015-08-19 09:53:28 -0400110 >>> os.path.commonprefix(['/usr/lib', '/usr/local/lib'])
111 '/usr/l'
Yury Selivanov80ac11f2015-08-17 23:43:43 -0400112
Yury Selivanovde115612015-08-19 09:53:28 -0400113 >>> os.path.commonpath(['/usr/lib', '/usr/local/lib'])
114 '/usr'
Georg Brandl116aa622007-08-15 14:28:22 +0000115
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700116 .. versionchanged:: 3.6
117 Accepts a :term:`path-like object`.
118
Georg Brandl116aa622007-08-15 14:28:22 +0000119
120.. function:: dirname(path)
121
Chris Jerdonek0b502ff2012-11-25 20:38:01 -0800122 Return the directory name of pathname *path*. This is the first element of
123 the pair returned by passing *path* to the function :func:`split`.
Georg Brandl116aa622007-08-15 14:28:22 +0000124
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700125 .. versionchanged:: 3.6
126 Accepts a :term:`path-like object`.
127
Georg Brandl116aa622007-08-15 14:28:22 +0000128
129.. function:: exists(path)
130
Richard Oudkerk2240ac12012-07-06 12:05:32 +0100131 Return ``True`` if *path* refers to an existing path or an open
132 file descriptor. Returns ``False`` for broken symbolic links. On
133 some platforms, this function may return ``False`` if permission is
134 not granted to execute :func:`os.stat` on the requested file, even
Georg Brandl116aa622007-08-15 14:28:22 +0000135 if the *path* physically exists.
136
Richard Oudkerk2240ac12012-07-06 12:05:32 +0100137 .. versionchanged:: 3.3
138 *path* can now be an integer: ``True`` is returned if it is an
139 open file descriptor, ``False`` otherwise.
140
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700141 .. versionchanged:: 3.6
142 Accepts a :term:`path-like object`.
143
Georg Brandl116aa622007-08-15 14:28:22 +0000144
145.. function:: lexists(path)
146
147 Return ``True`` if *path* refers to an existing path. Returns ``True`` for
148 broken symbolic links. Equivalent to :func:`exists` on platforms lacking
149 :func:`os.lstat`.
150
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700151 .. versionchanged:: 3.6
152 Accepts a :term:`path-like object`.
153
Georg Brandl116aa622007-08-15 14:28:22 +0000154
155.. function:: expanduser(path)
156
157 On Unix and Windows, return the argument with an initial component of ``~`` or
158 ``~user`` replaced by that *user*'s home directory.
159
160 .. index:: module: pwd
161
162 On Unix, an initial ``~`` is replaced by the environment variable :envvar:`HOME`
163 if it is set; otherwise the current user's home directory is looked up in the
164 password directory through the built-in module :mod:`pwd`. An initial ``~user``
165 is looked up directly in the password directory.
166
167 On Windows, :envvar:`HOME` and :envvar:`USERPROFILE` will be used if set,
168 otherwise a combination of :envvar:`HOMEPATH` and :envvar:`HOMEDRIVE` will be
169 used. An initial ``~user`` is handled by stripping the last directory component
170 from the created user path derived above.
171
172 If the expansion fails or if the path does not begin with a tilde, the path is
173 returned unchanged.
174
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700175 .. versionchanged:: 3.6
176 Accepts a :term:`path-like object`.
177
Georg Brandl116aa622007-08-15 14:28:22 +0000178
179.. function:: expandvars(path)
180
181 Return the argument with environment variables expanded. Substrings of the form
182 ``$name`` or ``${name}`` are replaced by the value of environment variable
183 *name*. Malformed variable names and references to non-existing variables are
184 left unchanged.
185
186 On Windows, ``%name%`` expansions are supported in addition to ``$name`` and
187 ``${name}``.
188
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700189 .. versionchanged:: 3.6
190 Accepts a :term:`path-like object`.
191
Georg Brandl116aa622007-08-15 14:28:22 +0000192
193.. function:: getatime(path)
194
Victor Stinner01b5aab2017-10-24 02:02:00 -0700195 Return the time of last access of *path*. The return value is a floating point number giving
Georg Brandl116aa622007-08-15 14:28:22 +0000196 the number of seconds since the epoch (see the :mod:`time` module). Raise
Andrew Svetlov618c2e12012-12-15 22:59:24 +0200197 :exc:`OSError` if the file does not exist or is inaccessible.
Georg Brandl116aa622007-08-15 14:28:22 +0000198
Georg Brandl116aa622007-08-15 14:28:22 +0000199
200.. function:: getmtime(path)
201
Victor Stinner01b5aab2017-10-24 02:02:00 -0700202 Return the time of last modification of *path*. The return value is a floating point number
Georg Brandl116aa622007-08-15 14:28:22 +0000203 giving the number of seconds since the epoch (see the :mod:`time` module).
Andrew Svetlov618c2e12012-12-15 22:59:24 +0200204 Raise :exc:`OSError` if the file does not exist or is inaccessible.
Georg Brandl116aa622007-08-15 14:28:22 +0000205
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700206 .. versionchanged:: 3.6
207 Accepts a :term:`path-like object`.
208
Georg Brandl116aa622007-08-15 14:28:22 +0000209
210.. function:: getctime(path)
211
212 Return the system's ctime which, on some systems (like Unix) is the time of the
Georg Brandlf6324942013-10-06 09:52:55 +0200213 last metadata change, and, on others (like Windows), is the creation time for *path*.
Georg Brandl116aa622007-08-15 14:28:22 +0000214 The return value is a number giving the number of seconds since the epoch (see
Andrew Svetlov618c2e12012-12-15 22:59:24 +0200215 the :mod:`time` module). Raise :exc:`OSError` if the file does not exist or
Georg Brandl116aa622007-08-15 14:28:22 +0000216 is inaccessible.
217
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700218 .. versionchanged:: 3.6
219 Accepts a :term:`path-like object`.
220
Georg Brandl116aa622007-08-15 14:28:22 +0000221
222.. function:: getsize(path)
223
Andrew Svetlov618c2e12012-12-15 22:59:24 +0200224 Return the size, in bytes, of *path*. Raise :exc:`OSError` if the file does
Georg Brandl116aa622007-08-15 14:28:22 +0000225 not exist or is inaccessible.
226
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700227 .. versionchanged:: 3.6
228 Accepts a :term:`path-like object`.
229
Georg Brandl116aa622007-08-15 14:28:22 +0000230
231.. function:: isabs(path)
232
Christian Heimesaf98da12008-01-27 15:18:18 +0000233 Return ``True`` if *path* is an absolute pathname. On Unix, that means it
234 begins with a slash, on Windows that it begins with a (back)slash after chopping
235 off a potential drive letter.
Georg Brandl116aa622007-08-15 14:28:22 +0000236
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700237 .. versionchanged:: 3.6
238 Accepts a :term:`path-like object`.
239
Georg Brandl116aa622007-08-15 14:28:22 +0000240
241.. function:: isfile(path)
242
Cheryl Sabellab3dd18d2018-01-14 23:57:51 -0500243 Return ``True`` if *path* is an :func:`existing <exists>` regular file.
244 This follows symbolic links, so both :func:`islink` and :func:`isfile` can
245 be true for the same path.
Georg Brandl116aa622007-08-15 14:28:22 +0000246
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700247 .. versionchanged:: 3.6
248 Accepts a :term:`path-like object`.
249
Georg Brandl116aa622007-08-15 14:28:22 +0000250
251.. function:: isdir(path)
252
Cheryl Sabellab3dd18d2018-01-14 23:57:51 -0500253 Return ``True`` if *path* is an :func:`existing <exists>` directory. This
254 follows symbolic links, so both :func:`islink` and :func:`isdir` can be true
255 for the same path.
Georg Brandl116aa622007-08-15 14:28:22 +0000256
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700257 .. versionchanged:: 3.6
258 Accepts a :term:`path-like object`.
259
Georg Brandl116aa622007-08-15 14:28:22 +0000260
261.. function:: islink(path)
262
Cheryl Sabellab3dd18d2018-01-14 23:57:51 -0500263 Return ``True`` if *path* refers to an :func:`existing <exists>` directory
264 entry that is a symbolic link. Always ``False`` if symbolic links are not
265 supported by the Python runtime.
Georg Brandl116aa622007-08-15 14:28:22 +0000266
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700267 .. versionchanged:: 3.6
268 Accepts a :term:`path-like object`.
269
Georg Brandl116aa622007-08-15 14:28:22 +0000270
271.. function:: ismount(path)
272
Larry Hastings3732ed22014-03-15 21:13:56 -0700273 Return ``True`` if pathname *path* is a :dfn:`mount point`: a point in a
274 file system where a different file system has been mounted. On POSIX, the
275 function checks whether *path*'s parent, :file:`path/..`, is on a different
276 device than *path*, or whether :file:`path/..` and *path* point to the same
277 i-node on the same device --- this should detect mount points for all Unix
278 and POSIX variants. On Windows, a drive letter root and a share UNC are
279 always mount points, and for any other path ``GetVolumePathName`` is called
280 to see if it is different from the input path.
281
282 .. versionadded:: 3.4
283 Support for detecting non-root mount points on Windows.
Georg Brandl116aa622007-08-15 14:28:22 +0000284
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700285 .. versionchanged:: 3.6
286 Accepts a :term:`path-like object`.
287
Georg Brandl116aa622007-08-15 14:28:22 +0000288
Zachary Warea13dab42014-10-10 16:03:14 -0500289.. function:: join(path, *paths)
Georg Brandl116aa622007-08-15 14:28:22 +0000290
Zachary Warea13dab42014-10-10 16:03:14 -0500291 Join one or more path components intelligently. The return value is the
292 concatenation of *path* and any members of *\*paths* with exactly one
293 directory separator (``os.sep``) following each non-empty part except the
294 last, meaning that the result will only end in a separator if the last
295 part is empty. If a component is an absolute path, all previous
296 components are thrown away and joining continues from the absolute path
297 component.
298
299 On Windows, the drive letter is not reset when an absolute path component
300 (e.g., ``r'\foo'``) is encountered. If a component contains a drive
301 letter, all previous components are thrown away and the drive letter is
302 reset. Note that since there is a current directory for each drive,
303 ``os.path.join("c:", "foo")`` represents a path relative to the current
304 directory on drive :file:`C:` (:file:`c:foo`), not :file:`c:\\foo`.
Georg Brandl116aa622007-08-15 14:28:22 +0000305
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700306 .. versionchanged:: 3.6
307 Accepts a :term:`path-like object` for *path* and *paths*.
308
Georg Brandl116aa622007-08-15 14:28:22 +0000309
310.. function:: normcase(path)
311
Benjamin Petersond23f8222009-04-05 19:13:16 +0000312 Normalize the case of a pathname. On Unix and Mac OS X, this returns the
313 path unchanged; on case-insensitive filesystems, it converts the path to
314 lowercase. On Windows, it also converts forward slashes to backward slashes.
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700315 Raise a TypeError if the type of *path* is not ``str`` or ``bytes`` (directly
316 or indirectly through the :class:`os.PathLike` interface).
317
318 .. versionchanged:: 3.6
319 Accepts a :term:`path-like object`.
Georg Brandl116aa622007-08-15 14:28:22 +0000320
321
322.. function:: normpath(path)
323
Terry Jan Reedyec6e1322013-03-17 15:21:26 -0400324 Normalize a pathname by collapsing redundant separators and up-level
325 references so that ``A//B``, ``A/B/``, ``A/./B`` and ``A/foo/../B`` all
326 become ``A/B``. This string manipulation may change the meaning of a path
327 that contains symbolic links. On Windows, it converts forward slashes to
Terry Jan Reedyf3460412013-03-17 15:28:10 -0400328 backward slashes. To normalize case, use :func:`normcase`.
Georg Brandl116aa622007-08-15 14:28:22 +0000329
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700330 .. versionchanged:: 3.6
331 Accepts a :term:`path-like object`.
332
Georg Brandl116aa622007-08-15 14:28:22 +0000333
334.. function:: realpath(path)
335
336 Return the canonical path of the specified filename, eliminating any symbolic
337 links encountered in the path (if they are supported by the operating system).
338
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700339 .. versionchanged:: 3.6
340 Accepts a :term:`path-like object`.
341
Georg Brandl116aa622007-08-15 14:28:22 +0000342
Benjamin Peterson409a1be2014-03-20 12:39:53 -0500343.. function:: relpath(path, start=os.curdir)
Georg Brandl116aa622007-08-15 14:28:22 +0000344
R David Murrayce10fab2013-07-12 17:43:11 -0400345 Return a relative filepath to *path* either from the current directory or
346 from an optional *start* directory. This is a path computation: the
347 filesystem is not accessed to confirm the existence or nature of *path* or
348 *start*.
Georg Brandl116aa622007-08-15 14:28:22 +0000349
Benjamin Petersonf650e462010-05-06 23:03:05 +0000350 *start* defaults to :attr:`os.curdir`.
351
Antoine Pitrouf10f1622010-12-12 20:17:29 +0000352 Availability: Unix, Windows.
Georg Brandl116aa622007-08-15 14:28:22 +0000353
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700354 .. versionchanged:: 3.6
355 Accepts a :term:`path-like object`.
356
Georg Brandl116aa622007-08-15 14:28:22 +0000357
358.. function:: samefile(path1, path2)
359
Brian Curtind40e6f72010-07-08 21:39:08 +0000360 Return ``True`` if both pathname arguments refer to the same file or directory.
Larry Hastings3732ed22014-03-15 21:13:56 -0700361 This is determined by the device number and i-node number and raises an
Martin Panter7462b6492015-11-02 03:37:02 +0000362 exception if an :func:`os.stat` call on either pathname fails.
Benjamin Petersonf650e462010-05-06 23:03:05 +0000363
Antoine Pitrouf10f1622010-12-12 20:17:29 +0000364 Availability: Unix, Windows.
Georg Brandl116aa622007-08-15 14:28:22 +0000365
Georg Brandlb3823372010-07-10 08:58:37 +0000366 .. versionchanged:: 3.2
367 Added Windows support.
Brian Curtinc7395692010-07-09 15:15:09 +0000368
Brian Curtin490b32a2012-12-26 07:03:03 -0600369 .. versionchanged:: 3.4
370 Windows now uses the same implementation as all other platforms.
371
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700372 .. versionchanged:: 3.6
373 Accepts a :term:`path-like object`.
374
Georg Brandl116aa622007-08-15 14:28:22 +0000375
376.. function:: sameopenfile(fp1, fp2)
377
378 Return ``True`` if the file descriptors *fp1* and *fp2* refer to the same file.
Benjamin Petersonf650e462010-05-06 23:03:05 +0000379
Brian Curtin62857742010-09-06 17:07:27 +0000380 Availability: Unix, Windows.
381
Georg Brandl61063cc2012-06-24 22:48:30 +0200382 .. versionchanged:: 3.2
383 Added Windows support.
Georg Brandl116aa622007-08-15 14:28:22 +0000384
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700385 .. versionchanged:: 3.6
386 Accepts a :term:`path-like object`.
387
Georg Brandl116aa622007-08-15 14:28:22 +0000388
389.. function:: samestat(stat1, stat2)
390
391 Return ``True`` if the stat tuples *stat1* and *stat2* refer to the same file.
Serhiy Storchakadab83542013-10-13 20:12:43 +0300392 These structures may have been returned by :func:`os.fstat`,
393 :func:`os.lstat`, or :func:`os.stat`. This function implements the
394 underlying comparison used by :func:`samefile` and :func:`sameopenfile`.
Benjamin Petersonf650e462010-05-06 23:03:05 +0000395
Brian Curtin490b32a2012-12-26 07:03:03 -0600396 Availability: Unix, Windows.
397
398 .. versionchanged:: 3.4
399 Added Windows support.
Georg Brandl116aa622007-08-15 14:28:22 +0000400
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700401 .. versionchanged:: 3.6
402 Accepts a :term:`path-like object`.
403
Georg Brandl116aa622007-08-15 14:28:22 +0000404
405.. function:: split(path)
406
Georg Brandl539c1652010-10-14 06:46:08 +0000407 Split the pathname *path* into a pair, ``(head, tail)`` where *tail* is the
408 last pathname component and *head* is everything leading up to that. The
409 *tail* part will never contain a slash; if *path* ends in a slash, *tail*
410 will be empty. If there is no slash in *path*, *head* will be empty. If
411 *path* is empty, both *head* and *tail* are empty. Trailing slashes are
412 stripped from *head* unless it is the root (one or more slashes only). In
413 all cases, ``join(head, tail)`` returns a path to the same location as *path*
Chris Jerdonek0b502ff2012-11-25 20:38:01 -0800414 (but the strings may differ). Also see the functions :func:`dirname` and
415 :func:`basename`.
Georg Brandl116aa622007-08-15 14:28:22 +0000416
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700417 .. versionchanged:: 3.6
418 Accepts a :term:`path-like object`.
419
Georg Brandl116aa622007-08-15 14:28:22 +0000420
421.. function:: splitdrive(path)
422
423 Split the pathname *path* into a pair ``(drive, tail)`` where *drive* is either
Mark Hammond5a607a32009-05-06 08:04:54 +0000424 a mount point or the empty string. On systems which do not use drive
Georg Brandl116aa622007-08-15 14:28:22 +0000425 specifications, *drive* will always be the empty string. In all cases, ``drive
426 + tail`` will be the same as *path*.
427
Mark Hammond5a607a32009-05-06 08:04:54 +0000428 On Windows, splits a pathname into drive/UNC sharepoint and relative path.
429
430 If the path contains a drive letter, drive will contain everything
431 up to and including the colon.
432 e.g. ``splitdrive("c:/dir")`` returns ``("c:", "/dir")``
433
434 If the path contains a UNC path, drive will contain the host name
435 and share, up to but not including the fourth separator.
436 e.g. ``splitdrive("//host/computer/dir")`` returns ``("//host/computer", "/dir")``
437
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700438 .. versionchanged:: 3.6
439 Accepts a :term:`path-like object`.
440
Georg Brandl116aa622007-08-15 14:28:22 +0000441
442.. function:: splitext(path)
443
444 Split the pathname *path* into a pair ``(root, ext)`` such that ``root + ext ==
445 path``, and *ext* is empty or begins with a period and contains at most one
446 period. Leading periods on the basename are ignored; ``splitext('.cshrc')``
447 returns ``('.cshrc', '')``.
448
Brett Cannon6fa7aad2016-09-06 15:55:02 -0700449 .. versionchanged:: 3.6
450 Accepts a :term:`path-like object`.
451
Georg Brandl116aa622007-08-15 14:28:22 +0000452
Georg Brandl116aa622007-08-15 14:28:22 +0000453.. data:: supports_unicode_filenames
454
Serhiy Storchakafbc1c262013-11-29 12:17:13 +0200455 ``True`` if arbitrary Unicode strings can be used as file names (within limitations
Victor Stinnerb55e4982010-09-11 00:22:12 +0000456 imposed by the file system).