2017-10-10 105 views
0

我正在使用Azure Batch和Python,我想從批處理任務中的共享空間內創建一個目錄。

按照docs

共享:此目錄提供讀取到的節點上運行的所有任務/寫訪問。節點上運行的任何任務都可以創建,讀取,更新和刪除此目錄中的文件。任務可以通過引用AZ_BATCH_NODE_SHARED_DIR環境變量來訪問此目錄。

想象,文件夾名爲test_dir

if not os.path.exists('test_dir'): 
    os.makedirs('test_dir') 

現在,如果我想要寫一個文件到該目錄是什麼?我不能使用:

with open('$AZ_BATCH_NODE_SHARED_DIR/test_dir/test.txt', 'a') as output: 
    output.write('hello\n') 

如何從$AZ_BATCH_NODE_SHARED_DIR獲得完整路徑?

回答

0

使用os.environ,它公開的當前環境的映射:

shared = os.environ['AZ_BATCH_NODE_SHARED_DIR'] 
with open(os.path.join(shared, 'test_dir', 'test.txt'), 'a') as output: 
相關問題