我的代码要求是这样的。
使用我的temp_name变量,我想搜索一个列表。如果列表中不存在,我想使用相同的。 如果它存在,那么我将计数增加1并再次搜索,直到找到一个不存在的唯一名称。
count = 1
name = department
temp_name = "name" + '-' + str(count)
我的清单如下:
departments {
department-1
department-7
department-2
department-6
department-9
}
请你看一下。
我基本上是通过他们的名字查询AWS中的所有EC2实例。
import boto3
ec2= boto3.resource('ec2')
# Get information for all running instances
running_instances = ec2.instances.filter(Filters=[{
'Name': 'instance-state-name',
'Values': ['running']}])
for instance in running_instances:
for tag in instance.tags:
if 'Name'in tag['Key']:
name = tag['Value']
print name
并希望使用不存在的唯一名称来旋转新实例。
答案 0 :(得分:0)
变量的名称和值之间存在一些混淆:
$(document).ready(function () {
$('#clientTable').DataTable({
"order": [[1, "asc"]],
"serverSide": true,
"processing": true,
"paging": true,
"bLengthChange": false,
"iDisplayLength": 10, //Here was the problem
您正在寻找name = department
temp_name = "name" + '-' + str(count)
等,但department-1
实际上包含temp_name
等。修复此问题,
name-1
然后,可能,
departments = ["department-1","department-7","department-2","department-6","department-9"]
count = 1
temp_name = "department-%d" % count
while temp_name in departments:
count += 1
temp_name = "department-%d" % count
print temp_name