実際には、いくつかのパスに移動していくつかのコマンドを実行する必要があり、以下はコードです
コード:
import os
present_working_directory = '/home/Desktop/folder'
現在私はfolder
if some_condition == true :
change_path = "nodes/hellofolder"
os.chdir(change_path)
print os.getcwd()
if another_condition == true:
change_another_path = "nodes"
os.chdir(change_another_path)
print os.getcwd()
**Result**:
'/home/Desktop/folder/nodes/hellofolder'
python: [Errno 1] No such file or directory
実際にここで起こっていることは、私が最初os.chdir()
にディレクトリを使用したときです。
'/home/Desktop/folder/nodes/hellofolder'
、
しかし、2番目のものについては、1つのフォルダーに戻ってファイルを実行する必要があります
'/home/Desktop/folder/nodes'
Pythonで1つのフォルダを元に戻す方法を誰にでも教えてもらえますか