What does sys.path.append("..") do?
Asked Answered
S

1

10

I bumped into this statement in a Python script: sys.path.append("..") I did some research, but I could not find what it does.

I know sys.path.append() function appends a path at the end of the PYTHONPATH list. But what does ".." stand for?

Needless to say, this Python scripts does not work if I comment the line.

Staton answered 18/12, 2018 at 13:53 Comment(3)
Possible duplicate of Importing modules from parent folderDissentient
It adds the .. to the paths that Python searches for imports, so you can import things from .. (which is the parent of the current directory) .Oto
Well, that is clear that it looks like it refers to parent directory, and it has been my first thought. Though, when I change sys.path.append("..") to sys.path.append(absolute-path-to-parent-directory), it does not work and throw a ModuleNotFoundError when I try to load a module from that directory...Staton
A
5

".." is a way of saying/referencing the parent of the current working directory.

Asaasabi answered 18/12, 2018 at 13:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.