如何从 $AZ_BATCH_NODE_SHARED_DIR 获取路径?
How do I get the path from $AZ_BATCH_NODE_SHARED_DIR?
我将 Azure Batch 与 Python 一起使用,我想通过批处理任务在共享 space 中创建一个目录。
根据 docs:
Shared: This directory provides read/write access to all tasks that run on a node. Any task that runs on the node can create, read, update, and delete files in this directory. Tasks can access this directory by referencing the AZ_BATCH_NODE_SHARED_DIR environment variable.
假设该文件夹名为 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
获取完整路径?
使用os.environ
,将当前环境公开为映射:
shared = os.environ['AZ_BATCH_NODE_SHARED_DIR']
with open(os.path.join(shared, 'test_dir', 'test.txt'), 'a') as output:
我将 Azure Batch 与 Python 一起使用,我想通过批处理任务在共享 space 中创建一个目录。
根据 docs:
Shared: This directory provides read/write access to all tasks that run on a node. Any task that runs on the node can create, read, update, and delete files in this directory. Tasks can access this directory by referencing the AZ_BATCH_NODE_SHARED_DIR environment variable.
假设该文件夹名为 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
获取完整路径?
使用os.environ
,将当前环境公开为映射:
shared = os.environ['AZ_BATCH_NODE_SHARED_DIR']
with open(os.path.join(shared, 'test_dir', 'test.txt'), 'a') as output: