Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does sys.path.append("..") do?

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.

like image 309
CDuvert Avatar asked Dec 18 '18 13:12

CDuvert


People also ask

Is SYS path append good practice?

It is generally not good practice to use manipulate sys. path within a python library or program. You should add the relevant paths to the PYTHONPATH in the calling environment for your python program: PYTHONPATH="/path/to/other/projects/directory:$PYTHONPATH" python ...

Is SYS path append temporary?

Appending a value to sys. path only modifies it temporarily, i.e for that session only. Permanent modifications are done by changing PYTHONPATH and the default installation directory.

What does the code below do SYS path append ('/ root mods ')?

sys. path. append('/root/mods') Removes all directory for mods.

How do I undo SYS path append?

To undo the sys. path. append , you just need to remove that line from your script. Since the path is only modified for your current script and not system wide until you edit the PYTHONPATH .


1 Answers

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

like image 81
Linny Avatar answered Sep 21 '22 21:09

Linny