Python3 os.pardir Method
Python3 OS File/Directory Methods
Overview
os.pardir() gets the parent directory (the level above) of the current directory, showing the directory name as a string.
Note: Windows and POSIX return ..
Syntax
The **pardir()** method syntax is as follows:
os.pardir
Parameters
-
none.
Return Value
Returns the parent directory of the current directory, defaulting to ..
Example
The following example demonstrates the use of the pardir() method:
Example
import
os
Output the default value ..
(
os
.
pardir
)
The output of the above program is:
..
Print the parent directory of the current directory:
Example
import
os
Current working directory
path
=
os
.
getcwd
(
)
(
"Current working directory: "
,
path
)
Parent directory
parent
=
os
.
path
.
join
(
path
,
os
.
pardir
)
Parent directory
(
"\nParent directory:"
,
os
.
path
.
abspath
(
parent
)
)
The output of the above program is:
当前工作目录: /Users/runoob/python
父目录: /Users/runoob