I am struggling to understand the values and variables properties of foreach.

Can someone please explain what exactly they do in the following example from the users guide?

I understand that the variable installedApplications comes from the registry read, but what about "key value name"? How is that set?


      <variables>key name value</variables>
            <md5 text="${key}" variable="md5"/>

asked 20 Mar '12, 13:05

wildcatz's gravatar image

accept rate: 0%

Was my answer and/or Python example confusing? If so, I could clarify further.

(23 Mar '12, 14:30) DevHopeful_2012

I believe the foreach in the example works with a list of lists because the return value of registryFind is a list and findall is set to true. Therefore, the foreach will iterate over the list, ${installedApplications}, but each element in the list is a list, itself. The example cleverly parses the list element by specifying a variable for each index. Something similar to the following:

installedApps = [('Notepad++', 'DisplayName', 'Notepad++'), ('Office14.STANDARD', 'DisplayName', 'Microsoft Office Standard 2010')]
for (key, name, value) in installedApps:
    print "Found Registry Entry:\\n\\tkey: %s\\n\\tname: %s\\n\\tvalue: %s" % (key, name, value)

Found Registry Entry:
    key: Notepad++
    name: DisplayName
    value: Notepad++
Found Registry Entry:
    key: Office14.STANDARD
    name: DisplayName
    value: Microsoft Office Standard 2010

answered 21 Mar '12, 01:35

DevHopeful_2012's gravatar image

accept rate: 9%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 20 Mar '12, 13:05

Seen: 1,489 times

Last updated: 23 Mar '12, 14:30