0

It was used lxml.iterparse and the code was checked with Pylint. I want to write the code without unused variable "event". How can I do this?

context = etree.iterparse(StringIO(xml))
for event, elem in context:
    print(elem.tag)
Elena
  • 109
  • 1
  • 8
  • Please show a complete input XML document, together with a complete Python script. Also, explain what your _goal_is. Thanks. Please read: http://stackoverflow.com/help/mcve. – Mathias Müller Feb 09 '17 at 16:53
  • 1
    It might help to use `for _, elem in context:` to indicate a "throwaway variable" (see http://stackoverflow.com/a/5893946/407651). – mzjn Feb 09 '17 at 20:38
  • 1
    Btw, `print elem.tag` must be `print(elem.tag)` (question is tagged with "python-3.x"). – mzjn Feb 09 '17 at 20:46
  • 1
    @Elena, you should post an actual answer (and accept it) so that it is clear that the problem has been solved. – mzjn Feb 10 '17 at 10:55

1 Answers1

0

resolved by using _ for throwaway variables (thanks mzjn).

context = etree.iterparse(StringIO(xml))
for _, elem in context:
    print(elem.tag)
Elena
  • 109
  • 1
  • 8