Bill Rosmus
Bill Rosmus

Reputation: 3011

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?

Upvotes: 5

Views: 18658

Answers (3)

Shashank Shekhar
Shashank Shekhar

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

kerim
kerim

Reputation: 2522

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

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

Upvotes: 12

Ry-
Ry-

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

Related Questions