Advanced example 1: the answer elements

In the previous examples the answer elements have been printed out by using

for item in answer.elements():
    print item.comment()

This chapter is here to help you if you need more control when dealing with the answer elements.

First of all, there is the sentence of text that matches the question. This sentence can be printed out by using

item.text

Then there is the description that can be bound to a text. This can be printed out by using

item.description

each answer element also contain a list of query: reply pairs, that can be printed out as in the following:

for pair in item.pairs:
    print pair.query + ':' + pair.reply

In the end, the lines

for item in answer.elements():
    print item.comment()

can be substituted with

for item in answer.elements():
    print item.text
    print item.description
    for pair in item.pairs:
        print pair.query + ':' + pair.reply

with output

the answer is a list
The chancellor is going to Berlin.
None
person:the chancellor