Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with XML exercise, Chapter 3 #6

Open
AJVicens opened this issue Mar 14, 2017 · 5 comments
Open

Problem with XML exercise, Chapter 3 #6

AJVicens opened this issue Mar 14, 2017 · 5 comments

Comments

@AJVicens
Copy link

AJVicens commented Mar 14, 2017

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!

@kjam
Copy link
Collaborator

kjam commented Mar 14, 2017

@AJVicens Thanks for reporting this! Can you let me know what version of Python and what operating system you are using so I can try replicating? I'm glad you found a way -- good experimentation! 👍

@AJVicens
Copy link
Author

Updated. Sorry about that!

@kjam
Copy link
Collaborator

kjam commented Mar 14, 2017

No worries at all! My Macbook is at home, so I will try it there first. What was the response when you simply printed list(tree). Was it an error or just nothing happened? (final question for now, I promise!) 😄

@AJVicens
Copy link
Author

Sorry for my delay. It was that nothing happened. Given my noob-ness, it could be that I was just doing something wrong. I can try to run through that issue again soon and update the issue.

@kjam
Copy link
Collaborator

kjam commented May 1, 2017

Hi there,

Following up with this -- it works for me in IPython on 2.7.6. If you have time, can you try running it in IPython and see if you get the same results? You can install with pip or conda install ipython. Let me know how it goes and thanks again for your help! :)

-kj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants