从bash调用python,如何更改python工作目录?

Eri*_*ric 1 python bash working-directory

我有一个像这样的bash脚本:

# gets all relevant files in the directory
cp ../update_files/* ./transfer_dir

# copy the python scripts to that directory
cp ../tools/update_tool/* ./transfer_dir

# execute the python scripts 
python ./transfer_dir/merge.py
Run Code Online (Sandbox Code Playgroud)

现在的问题是,当我尝试执行python脚本时,它认为"工作目录"是.,而不是./transfer_dir,我不能提交先前复制的update_files文件

我怎么能改变呢?我不想太多地修改我的python脚本,因为它们大多与位置无关.

unu*_*tbu 7

用途cd:

cd transfer_dir
# execute the python scripts 
python merge.py
# restore old directory
cd ..                         
Run Code Online (Sandbox Code Playgroud)

  • @Eric:能够嘲笑自己是件好事; 让你免于过多的溃疡. (2认同)