代码之家  ›  专栏  ›  技术社区  ›  Milister

如何解析列表Python

  •  -1
  • Milister  · 技术社区  · 6 年前

    https://github.com/omni-lchen/zabbix-cloudwatch/blob/master/awsLLD.py

    def getEBS(a, r):
        account = a
        aws_account = awsAccount(account)
        aws_access_key_id = aws_account._aws_access_key_id
        aws_secret_access_key = aws_account._aws_secret_access_key
        aws_region = r
        #component = c
        # Init LLD Data
        lldlist = []
        llddata = {"data":lldlist}
    
        # Connect to EC2 service
        conn = awsConnection()
        conn.ebsConnect(aws_region, aws_access_key_id, aws_secret_access_key)
        ebsConn = conn._aws_connection
    
        # Save EBS function results in a list
    
        functionResultsList = []
    
        # Save volume names in a list
    
        tdata = []
    
        # Get a list of EBS volumes
    
        functionResults = ebsConn.get_all_volumes()
    

    输出:

    [Volume:vol-029213f06d66eadac, Volume:vol-00fbd5dfaebd79e83, Volume:vol-0eeb126d13ecf0eed, Volume:vol-09a1f3446b3f78ea5]
    

    vol-029213f06d66eadac
    vol-0eeb126d13ecf0eed
    vol-09a1f3446b3f78ea5
    

    我知道我需要写一些东西,比如:

    for la in functionResultsList:
     print la[0]
    

    但不知道如何继续

    1 回复  |  直到 6 年前
        1
  •  0
  •   Milister    6 年前

    删除列表并使用:

     for la in range(len(functionResults)):
    
          print functionResults[la]
    

    Volume:vol-029213f06d66eadac
    Volume:vol-00fbd5dfaebd79e83
    Volume:vol-0eeb126d13ecf0eed
    Volume:vol-09a1f3446b3f78ea5
    

    对python还不太熟悉,也不知道实际的列表是什么——但我不认为这是downwote的原因