python-3.xsys.path

sys.path.append("../../../") and sys.path.append("..")


In one program, I noticed that author add two lines

sys.path.append("../../../")
sys.path.append("..")

Is the second path.add redundant?


Solution

  • ".." moves you one level up in the directory tree from where you are. So multiple .. moving you further up that many level.

    Sys.path is a list of directories where the Python interpreter searches for modules. you may find through print(sys.path). Please note it's a list.

    The sys.path.append() method is used to append the path that we want to the existing list.

    So second one is not redundant, you are the who added it...