amazon-web-services - 如何调用在 __init__ 方法中初始化的类对象?
问题描述
我有一个 s3class,它有一个__s3
配置了 s3 访问密钥对的属性。
class s3class():
def __init__(self, access, secret, bucket_name):
self.__bucket = bucket_name
self.__s3 = boto3.client('s3',
self.__access,
self.__secret)
import s3class
## do something here##
obj = s3class()
obj.__s3.download_file('prefix/filename.csv')
我想download_file
在另一个导入 s3class 的模块中使用 __s3 对象调用 boto3 特定方法。当我将 __s3 对象引用为 ob.__s3 时,我得到 AttributeError 对象 __s3 未找到。
解决方案
如果你的模块包含s3class
类被调用s3class.py
,那么你需要:
from s3class import s3class
推荐阅读
- oracle - 使用二进制格式的 EBCDIC 文件的外部表 Oracle - 错误 KUP-03003
- java - 如何从 dockerized spring boot 连接 dockerized couchbase 服务器
- python - ValueError:找不到表
- wordpress - wordpress 中的站点 URL 和管理 URL 短代码问题
- javascript - Node.js 和 Express:路由器内部的函数返回值
- reactjs - 忽略反应钩子上缺少的依赖项 es-lint 警告是否安全?
- javascript - TypeError: undefined is not an object (评估'_this2.props.navigation.navigate')
- angular - 无法读取未定义的属性“dtInstance”
- node.js - Passport Js自定义回调函数不调用下一个中间件
- javascript - 使用文件类型输入时将控制更改为未控制