5

同僚が Python のインストールで問題を抱えています。以下のコードを実行すると、現在の作業ディレクトリの代わりに from'C:\my\folder\''C:\'返されます。私または他の誰かが私たちのシステムでスクリプトを実行すると、'C:\my\folder\'.

一部のグローバル設定が問題の原因であると想定しているため、Python をアンインストールし、ローカルの Python2.7 フォルダーを削除し、レジストリを消去して Python を再インストールしてもらいましたが、まだ機能していません。

注: 多数のレガシー スクリプトがあるため、subprocess を使用するようにそれらすべてを修正することは現実的ではありません。:(

何か案は?

環境: Windows XP、Python 2.7

import os

#
#  This test script demonstrates issue on the users computer when python invokes
#  a subshell via the standard os.system() call.
#

print "This is what python thinks the current working directory is..."
print os.getcwd()
print
print

print "but when i execute a command *from* python, this is what i get for the current working directory"
os.system('echo %cd%')

raw_input()
4

2 に答える 2

7

このようなことを試すこともできます

os.chdir("C:\\to\\my\\folder")
print os.system("echo %CD%")
raw_input()

また、現在の作業ディレクトリを取得するには、別のアプローチを使用します

cur_dir = os.path.abspath(".")
于 2013-08-05T21:02:19.387 に答える