当我执行此代码时,它返回 None,但我想像循环中那样打印整数,有人知道为什么吗?
import boto3
client = boto3.client('autoscaling')
clearesponse = client.describe_auto_scaling_groups(
AutoScalingGroupNames=[
'XXXX',
])
for reservation in clearesponse ['AutoScalingGroups']:
test=print(reservation['DesiredCapacity'])
nb_desired_cap = test
print (nb_desired_cap)
print (test)
运行:
python 描述实例.py
4
无
无
运行代码并希望在其他变量中捕获结果 4 以用于代码的其他部分
这是因为
print
函数返回 None
。
>>> result = print("Hello, World!")
Hello, World!
>>> result is None
True
我不确定您希望代码执行什么操作,但您可能希望为变量分配除
print
返回的结果之外的其他内容。