Skip to content

Problem with XML exercise, Chapter 3 #6

@AJVicens

Description

@AJVicens

Hello,

I was working through the exercises and had a problem when I tried:

from xml.etree import ElementTree as ET

tree = ET.parse('data-text.xml')
root = tree.getroot()


print list(root) 

(pages 57-61). It wouldn't list the elements in the list. I ended up writing a for loop to get it to look like the example in the book (bottom of page 60, top of page 61):

import xml.etree.ElementTree as ET

tree = ET.parse('data-text.xml')
root = tree.getroot()

# data = root.find('Data')

for element in root:
	print element

Not sure if I did that correctly or efficiently, but this worked!

Thank you for writing the book.

Edit:
Python version:

Python 2.7.10 (default, Jul 30 2016, 19:40:32)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Mac OS: Sierra 10.12.3

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions