gpt4 book ai didi

python - 如何在Python sh模块中设置当前工作目录?

转载 作者:行者123 更新时间:2023-12-02 11:41:42 25 4
gpt4 key购买 nike

有没有办法在调用 Python sh 时设置当前工作目录模块?

我希望能够在与我当前所在的目录不同的目录中执行命令 --- 并且仅执行命令 --- 。大致如下:

import sh
foo = sh.ls(_current_directory="/tmp")

那就太好了。

最佳答案

使用_cwd parameter根据每个命令设置当前工作目录:

import sh
print(sh.ls(_cwd='/tmp'))

这适用于任何命令,而不仅仅是 sh.ls

关于python - 如何在Python sh模块中设置当前工作目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39902365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com