patrick vrijlandt added the comment: Dear Eli,
According to the XPath spec, the 'position' as can be used in xpath expressions, should be positive. However, the current implementation (example below from 3.3.0) accepts some values that should not be ok. Therefore, I do not agree that it behaves correctly. Garbage positions should return [] or an exception, not a value. And if you accept one value before the first position, you should accept them all. DATA = '''<?xml version="1.0"?> <data> <country name="Liechtenstein"> <rank updated="yes">2</rank> <year>2008</year> <gdppc>141100</gdppc> <neighbor name="Austria" direction="E"/> <neighbor name="Switzerland" direction="W"/> </country> <country name="Singapore"> <rank updated="yes">5</rank> <year>2011</year> <gdppc>59900</gdppc> <neighbor name="Malaysia" direction="N"/> </country> <country name="Panama"> <rank updated="yes">69</rank> <year>2011</year> <gdppc>13600</gdppc> <neighbor name="Costa Rica" direction="W"/> <neighbor name="Colombia" direction="E"/> </country> </data> ''' import xml.etree.ElementTree as ET root = ET.XML(DATA) print(root) for XP in (['./country'] + ['./country[%d]' % i for i in range(-1, 5)] + ['./country[last()%+d]' % i for i in range(-3, 5)]): print('{:20}'.format(XP), [elem.get('name') for elem in root.findall(XP)]) ## OUTPUT: ## <Element 'data' at 0x03CD9BD0> ## ./country ['Liechtenstein', 'Singapore', 'Panama'] ## ./country[-1] [] ## ./country[0] ['Panama'] ## ./country[1] ['Liechtenstein'] ## ./country[2] ['Singapore'] ## ./country[3] ['Panama'] ## ./country[4] [] ## ./country[last()-3] [] ## ./country[last()-2] ['Liechtenstein'] ## ./country[last()-1] ['Singapore'] ## ./country[last()+0] ['Panama'] ## ./country[last()+1] ['Liechtenstein'] ## ./country[last()+2] ['Singapore'] ## ./country[last()+3] ['Panama'] ## ./country[last()+4] [] ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue12323> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com