python - TypeError using xml.etree.ElmentTree -


i'm trying test attributes xml file against numbers. when run type() on attributes (in case currentnote):

import xml.etree.elementtree et tree = et.parse('booze.xml') root = tree.getroot() note in root.iter("note"):     currentnote = note.get("default-x")     print type(currentnote) 

the type prints <type = 'str'>

however, if change last line this:

print type(int(currentnote)) 

i this:

typeerror: int() argument must string or number, not 'nonetype' 

not sure what's going on - seems i'm misunderstanding etree parser returning...

currentnote = note.get("default-x") 

get returns none default if there no match key.

you cannot make integer nonetype.

in [51]: int(none) --------------------------------------------------------------------------- typeerror                                 traceback (most recent call last) <ipython-input-51-3f3b1d3c7325> in <module>() ----> 1 int(none)  typeerror: int() argument must string or number, not 'nonetype' 

you should print note in loop confirm data how expect be.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -