Using ".." instead of os.pardir not an issue unless you want to maintain compatibility with the classic Mac OS ( predecessor of OS X ) in which
- Parent directory is denoted by
::
- Directory separator is denoted by
:
- Current directory is also denoted by
:
You can check this by
import macpath
print(macpath.pardir) #print parent dir
print(macpath.curdir) #print current dir
print(macpath.sep) #print dir separator
The os module imports pardir from os.path module.
Importing macpath imports os.path of classic Mac OS in other operating systems. Similarly ntpath is for Windows and posixpath for POSIX systems.
Using os.pardir is also useful to maintain readability of the code.
Note: using "../../../../../" is a bad idea in windows because here the directory separator is hard coded too and windows uses "\" as default directory separator (os.sep) . This directory separator is used by os.path.join(). So the resulting path will look hideous with mixed slashes. There is no compelling reason to stop you from using it and of course mixed slashes can be corrected with os.path.normpath()