Python work program crash not working properly?

I am new to python and have been trying to figure this out in a few hours. I want to change the working directory using os in my script using

os.chdir("~") # not working.

os.getcwd #--> "/home/pi/Documents"

#I want to change into a subfolder I tried following
"subfolder"
"subfolder/"
"~../subfolder"
"/subfolder"

I tried

sys.path.append. 
+4
source share
2 answers

if you are in the / home / pi / Dokuments directory and you want to go to / home / pi / Dokuments / subfolder , you can try the following:

os.chdir(os.path.join(os.getcwd(), "subfolder"))
+1
source

In the shell, it ~refers to the home directory of the calling user ( $HOME).

os.chdir . , os.chdir("~") cd ~ ( ), .

os.path.expanduser ~ $HOME:

os.chdir(os.path.expanduser('~'))

, os.path.expanduser ~user, $HOME user.

+6

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


All Articles