Formatting data from a python array
<p>I'm learning python for the first time.
I have an aim which is to take data from an API and output it as xml.</p>

<p>The output is stored in an array ("projectData"), here is an example of the output:</p>

<pre><code>[{'code': 'demo',
 'created_at': datetime.datetime(2008, 6, 11, 7, 35, 19, tzinfo=&lt;api.LocalTimezone object at 0x10072ab10&gt;),
 'created_by': None,
 'id': 4,
 'image': 'https://website.com/files/0000/0000/blah.jpg',
 'name': 'Demo Project',
 'description': 'This is for demonstration purposes',
 'due': '2009-05-30',
 'start': '2009-05-06',
 'status': 'Active',
 'stype': 'Demo',
 'tag_list': [],
 'type': 'Project',
 'updated_at': datetime.datetime(2009, 5, 27, 1, 41, 55, tzinfo=&lt;api.LocalTimezone object at 0x10072ab10&gt;),
 'updated_by': {'id': 24, 'name': 'Test', 'type': 'HumanUser'},
 'users': [{'id': 19, 'name': 'User 1', 'type': 'HumanUser'},
           {'id': 18, 'name': 'User 2', 'type': 'HumanUser'},
           {'id': 17, 'name': 'User 3', 'type': 'HumanUser'},
           {'id': 16, 'name': 'User 4', 'type': 'HumanUser'},
           {'id': 15, 'name': 'User 5', 'type': 'HumanUser'},
           {'id': 14, 'name': 'User 6', 'type': 'HumanUser'},
           {'id': 13, 'name': 'User 7', 'type': 'HumanUser'},
           {'id': 12, 'name': 'User 8', 'type': 'HumanUser'},
           {'id': 20, 'name': 'Client 1', 'type': 'HumanUser'}]},
</code></pre>

<p>(etc.)</p>

<p>I've written some code which will output it as xml like so:</p>

<pre><code>for _project in projectData:
  print "&lt;Project&gt;"
  for key in _project:
    value = _project[key]
    print "\t&lt;" + str(key) + "&gt;" + str(value) + "&lt;/" + str(key) + "&gt;"
  print("&lt;/Project&gt;\n")
</code></pre>

<p>Which actually gives me a result that works for me.</p>

<p>However, because I'm new to this, I suspect that this isn't a very efficient approach, and may be susceptible to all sorts of bugs, I was hoping that someone more knowledgeable might have some pointers for me. The next thing I want to try with this is make it recursive, so that the "updated_by" element for example returns its own xml</p>

<p>Thanks.</p>
