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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CDuvert
  • 367
  • 1
  • 3
  • 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

5

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

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Linny
  • 818
  • 1
  • 9
  • 22