これが私が基本的にやろうとしていることです:
import sh, os
with sh.cd('/tmp'):
print os.getcwd()
print os.getcwd()
ただし、次のエラーが表示されます
line 3, in <module>
with sh.cd('/tmp'):
AttributeError: __exit__
ここで何が欠けていますか?コンテキスト内でディレクトリを変更する代替ソリューションはありますか?
これが私が基本的にやろうとしていることです:
import sh, os
with sh.cd('/tmp'):
print os.getcwd()
print os.getcwd()
ただし、次のエラーが表示されます
line 3, in <module>
with sh.cd('/tmp'):
AttributeError: __exit__
ここで何が欠けていますか?コンテキスト内でディレクトリを変更する代替ソリューションはありますか?
sh
現在pushd()
のディレクトリを一時的に変更するためのコンテキストマネージャとして使用できる機能が追加されました:
import sh
with sh.pushd("/tmp"):
sh.touch("a_file")
https://amoffat.github.io/sh/sections/command_class.html?highlight=pushd#pushdを参照してください