【发布时间】:2016-05-24 00:14:44
【问题描述】:
如果我使用 boto3 创建到 aws-ec2 的连接,它的返回类型为 boto3.resources.factory.ec2.ServiceResource
import boto3
cnxn = boto3.Session().resource('ec2')
type(cnxn)
>> boto3.resources.factory.ec2.ServiceResource
我希望能够将其用作类型提示的类型。但是,如果我尝试引用它,则会出现错误。
boto3.resources.factory.ec2.ServiceResource
AttributeError: module 'boto3.resources.factory' has no attribute 'ec2'
有没有办法将这些类型用作提示?
编辑:导入也不起作用
import boto3.resources.factory.ec2
>> ImportError: No module named 'boto3.resources.factory.ec2'; 'boto3.resources.factory' is not a package
【问题讨论】:
-
也许你需要做
import boto3.resources.factory.ec2? -
这给出了 ImportError - 请参阅编辑。
-
import boto3.ec2怎么样(如this question 中的建议)?如果你用谷歌搜索那个 AttributeError 消息,你会发现人们遇到类似错误的各种页面;其中一些可能会对您有所帮助。 -
说明你为什么要“引用”该类型?您不能引用类型。即使要知道变量是否属于特定类型,我也只是使用表达式。
标签: python amazon-ec2 python-3.5 boto3