python - 将文件作为参数的脚本没有看到文件,给出没有这样的文件或目录
问题描述
我有一个 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[] 错误?
解决方案
当我运行脚本时工作python3 script.py /tmp/file.txt
推荐阅读
- c# - 正则表达式长度如何工作?
- apache-spark - XGBoost-Spark 在训练期间做什么以及如何优化其资源使用?
- python - tf.saved_model.simple_save 可以用来为 C++ 创建 SavedModel 吗?
- docker - 如何使用 docker cp 将多个文件从容器复制到主机
- angular - 订阅多个 observable
在 foreach 循环中? - sql - 获取 ORA-06502:PL/SQL:数字或值错误:SQL 触发器中的字符到数字转换错误
- html - 使用 smoothState.js 链接不会指向二级页面
- xcode - turicreate (turicreate-5.0b2) 中的对象检测返回空预测数组
- android - 在打开另一个 GPS 应用程序之前,地理围栏随机无法触发
- java - Java 如果资源文件夹不存在,则在资源文件夹上创建一个空的 .ser 文件