How to jump to one or more levels using os.chdir with '..' as arguments

How to change the path in Python using ".." to go down one or more levels as an argument in os.chdir (). So if I am in / home / usr / one and I want to go to the "home" directory, then the argument "../ .." in chdir will do this. Will I end the argument in some other function?

0
source share
1 answer

As you say in your question, if you are in a directory /home/usr/one os.chdir('../../'), you will be taken to /home/.

You can confirm this by calling:

os.getcwd()

. . , chdir() .

:

, os.chdir() script , , script . , /home/usr/one script python myscript.py, , os.chdir() script, script; /home/usr/one.

0

Source: https://habr.com/ru/post/1656271/


All Articles