首页 > 解决方案 > 将文件作为参数的脚本没有看到文件,给出没有这样的文件或目录

问题描述

我有一个 python 脚本,它将文件作为参数并将该文件推送到 Azure Blob 存储。作为参考,我的脚本是:

#!/usr/bin/env python3
import os, sys

from azure.storage.blob import BlockBlobService
from azure.storage.blob import ContentSettings

storage_account = os.getenv('AZURE_STORAGE_ACCOUNT')
storage_container = os.getenv('AZURE_CONTAINER_NAME')
access_key = os.getenv('AZURE_ACCESS_KEY')

filename = sys.argv[1]

bbs = BlockBlobService(
    account_name = storage_account,
    account_key = access_key
)

bbs.create_blob_from_path(storage_container, filename, filename)

当我使用有效路径的参数运行上述代码时,/tmp/file.txt我得到的唯一返回是:

: No such file or directory.

如果我加载 REPL 并一次执行每一行,但将第 8 行替换为:

filename = '/tmp/file.txt'

然后它工作正常。我是否以某种方式使用了 sys.argv[] 错误?

标签: pythonpython-3.xbash

解决方案


当我运行脚本时工作python3 script.py /tmp/file.txt


推荐阅读