This question already has an answer here:
这个问题在这里已有答案:
- Temporarily change current working directory in bash to run a command [duplicate] 3 answers
- 暂时更改bash中的当前工作目录以运行命令[复制] 3个答案
I have a python script, which generates files. All i want is to force it to write the files in a specific folder. Right now i have to do 3 steps:
我有一个生成文件的python脚本。我想要的是强制它写入特定文件夹中的文件。现在我必须做3个步骤:
cd foo
python ../awesome_script.py
cd ..
Is there any nice solution, where i can do this in one line, either using some external command, or directly in the python interpreter?
有没有什么好的解决方案,我可以在一行中使用一些外部命令,或直接在python解释器中执行此操作?
I am searching for something like:
我正在寻找类似的东西:
python -f foo awesome_script.py
or
要么
cd_in_and_out_program foo awesome_script.py
This instruction will be in a makefile afterwards, so it can be ugly.
之后这个指令将在一个makefile中,所以它可能很难看。
1 个解决方案
#1
3
If the problem is just "one line":
如果问题只是“一行”:
cd foo; python ../awesome_script.py; cd ..
will do
会做
#1
3
If the problem is just "one line":
如果问题只是“一行”:
cd foo; python ../awesome_script.py; cd ..
will do
会做