cannot concatenate 'str' and 'instance'
concatenation, python, tkinter
Solution
Let me reproduce with a simpler example:
v = 42
query = ('what is ' + v)
You would get:
TypeError: cannot concatenate 'str' and 'int' objects
But now, if you simply call `str`:
query = ('what is ' + str(v))
That will work. So you only have to make sure `str(query)` returns what you expect. Be careful, I don't know what kind of object you are manipulating, but you should check if there is any method to get the string representation of it.
Related:
- TypeError: cannot concatenate 'str' and 'instance' objects (python urllib)
- Python: TypeError: cannot concatenate 'str' and 'int' objects
- Cannot concatenate 'str' and 'list' objects
- TypeError: cannot concatenate 'str' and 'int' objects TypeError: cannot concatenate 'str' and 'type' objects
Problem
I have a program using GUI elements and returns the error ``` cannot concatenate 'str' and 'instance' objects ``` The Code is: ``` def PeopleSearch(): query = SearchTerm query = ('what is '+ query) string = ("<center><font size = 14> " + query + ' </font></center><br><img src =picture') j = 0 try: gs = GoogleSearch(query) gs.results_per_page = 100 results = gs.get_results() ``` The indentations have been changed. Hmm. SearchTerm is basically from a textbox.
Related problems
- TypeError: cannot concatenate 'str' and 'int' objects
- TypeError: cannot concatenate 'str' and 'type' objects
- "TypeError: cannot concatenate 'str' and 'int' objects" when trying to use printf-style formatting
- TypeError: cannot concatenate 'str' and 'instance' objects (python urllib)
- Cannot concatenate 'str' and 'list' objects