10

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

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

Needless to say that this python scripts does not work if I comment the line.

CDuvert
  • 357
  • 1
  • 2
  • 14
  • 1
    Possible duplicate of [Importing modules from parent folder](https://stackoverflow.com/questions/714063/importing-modules-from-parent-folder) – Alex Dec 18 '18 at 13:54
  • 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) . – khelwood Dec 18 '18 at 13:57
  • 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... – CDuvert Dec 18 '18 at 14:15

1 Answers1

4

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

vinzee
  • 17,022
  • 14
  • 42
  • 60
Linny
  • 750
  • 1
  • 7
  • 21