2 Replies Latest reply on May 12, 2015 9:14 AM by mlampe

    Looking for better way to iterate through nodes


      Currently I am doing

      results = swis.query(sql_query)

      in order to populate a list of nodes depending on which SWQL query I am using.  I suppose I don't fully understand the syntax, but I am looping through this list by doing:



      for x in xrange(10000):
        uri = results['results'][x][IP_Address]



      I would like to have a better way to iterate through this list, but I don't fully understand how the list is generated and what results['results'][x][IP_Address] is doing.  I'd like some help understanding this further in order to hopefully come up with a cleaner way to iterate through the results list.

        • Re: Looking for better way to iterate through nodes

          swis.query(swql) returns an dictionary with a 'results' key. This value associated with the 'results' key property holds a list of dictionaries: the rows returned by your query. Each row is represented as a dictionary with a value for each property that was selected in your query.


          I'm not sure what you mean by a "better" way to iterate. Here's a variation:


          results = swis.query('SELECT Uri FROM Orion.Nodes')
          for node in results['results']:
               uri = node['Uri']
               swis.update(uri, ...)