Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenating strings then printing

print ("Tag Value " + i.tags.get('Name'))

gives me:

  File "./boto_test.py", line 19, in main
    print ("Tag Value" + i.tags.get('Name'))
TypeError: cannot concatenate 'str' and 'NoneType' objects

What is the correct way to do this?

like image 519
Bill Rosmus Avatar asked Dec 27 '12 18:12

Bill Rosmus


2 Answers

Or just convert whatever you get from i.tags to string:

print ("Tag Value " + str(i.tags.get('Name')))
like image 177
kerim Avatar answered Sep 29 '22 00:09

kerim


i.tags doesn’t contain a 'Name' key. What should the result be for None? Just pass it as a second argument to get:

print ("Tag Value " + i.tags.get('Name', 'None'))
like image 37
Ry- Avatar answered Sep 28 '22 23:09

Ry-