Reputation: 3011
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?
Upvotes: 5
Views: 18658
Reputation: 1
Try converting it to the string data type by str()
function.
Use the following code for the same line:
print ("Tag Value" + str(i.tags.get('Name')))
Upvotes: -1
Reputation: 2522
Or just convert whatever you get
from i.tags
to string:
print ("Tag Value " + str(i.tags.get('Name')))
Upvotes: 12
Reputation: 225281
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'))
Upvotes: 1