S
S
semen79072020-05-19 12:39:37
Python
semen7907, 2020-05-19 12:39:37

How to output variables from a loop?

There is this code:

for objItem in colItems:
                    if objItem.Caption != None:
                        print("Caption:" + objItem.Caption)
                        print("Command:" + objItem.Command)
                        print("User:" + objItem.User)

return self.wfile.write('<p>{}<p>'.format(objItem.Caption).encode('utf-8')) # вывод на веб странице


How can I make sure that all values ​​of objItem.Caption are displayed in return and not just the last one

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-05-19
@semen7907

captions = []
for objItem in colItems:
    if objItem.Caption != None:
        print("Caption:" + objItem.Caption)
        print("Command:" + objItem.Command)
        print("User:" + objItem.User)
        captions.append('<p>{}<p>'.format(objItem.Caption))

captions = '\n'.join(captions)
return self.wfile.write(captions.encode('utf-8'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question