Re: Key error on del attribute?
kristian kvilekval <kris <at> cs.ucsb.edu>
2009-08-04 23:34:08 GMT
On Tue, 2009-08-04 at 16:16 -0700, John Lovell wrote:
> On Ubuntu 9.04 I get a KeyError thrown. Can you provide a list of versions like the below?
>
> python: 2.6.2
> lxml.etree: (2, 1, 5, 0)
> libxml used: (2, 6, 32)
> libxml compiled: (2, 6, 32)
> libxslt used: (1, 1, 24)
> libxslt compiled: (1, 1, 24)
Bizarre .. your right it works in python..
it's the error parsing in ipython that runs into trouble:
Not sure if the bug is in ipython or lxml but no matter.
lxml.etree: (2, 1, 5, 0)
libxml used: (2, 6, 32)
libxml compiled: (2, 6, 32)
libxslt used: (1, 1, 24)
libxslt compiled: (1, 1, 24)
--------------------------------------------------------------------
Python 2.5.2 (r252:60911, Jan 4 2009, 21:59:32)
Type "copyright", "credits" or "license" for more information.
IPython 0.8.4 -- An enhanced Interactive Python.
In [3]: a=etree.Element('a', z='1', x='2')
In [4]: del a.attrib['x']
In [5]: del a.attrib['x']
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (3059, 0))
-------------------------------------------------
$ python
Python 2.5.2 (r252:60911, Jan 4 2009, 21:59:32)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=etree.Element('a', z='1', x='2')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'etree' is not defined
>>> from lxml import etree
>>> a=etree.Element('a', z='1', x='2')
>>> del a.attrib['x']
>>> del a.attrib['x']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "lxml.etree.pyx", line 1857, in lxml.etree._Attrib.__delitem__
(src/lxml/lxml.etree.c:18787)
File "apihelpers.pxi", line 435, in lxml.etree._delAttribute
(src/lxml/lxml.etree.c:31747)
KeyError: 'x'
> This should help...
> http://codespeak.net/lxml/2.0/FAQ.html#i-think-i-have-found-a-bug-in-lxml-what-should-i-do
>
Thanks,