Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

Instead of using os.path.curdir, we can use os.path.abspath(os.path.curdir)

Why do we need to include a useless variable at os.path module? Why can't we have os.path.curdir as a function that does the os.path.abspath ?

Why does os.path.curdir exist? Is there any reason behind this?

1 Answer

0 votes
by (26.4k points)

Here, It is a Constant, like os.path.sep

o denote the current directory, platforms except POSIX and Windows uses a different value

In Old Macintosh its : , whereas on Risc OS it's @

To make platform-agnostic the value is used throughout the standard library

Instead of using os.path.abspath(), we can use os.getcwd(), which uses the function under hood for turning os.path.curdir into the current working directory.

This is the POSIX implementation of abspath():

def abspath(path):

    """Return an absolute path."""

    if not isabs(path):

        if isinstance(path, _unicode):

            cwd = os.getcwdu()

        else:

            cwd = os.getcwd()

        path = join(cwd, path)

    return normpath(path)

For more details about python, refer to the tutorial on Python online course 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
0 votes
4 answers
0 votes
1 answer

Browse Categories

...