Python Forum
TypeError: __str__ returned non-string (type tuple)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: __str__ returned non-string (type tuple)
TypeError: __str__ returned non-string (type tuple)
The code are follow
from BTreeWordFinder import *
from BalancedBTree import *
class BalancedBTreeWordFinder(BTreeWordFinder):
'' 'binary search class implemented with a balanced binary tree; inherits from BTreeWordFinder and thus takes advantage of its methods' ''
def __init__(self, file, btree=None):
'' 'Builder methods' ''
BTreeWordFinder.__init__(self, file, btree)
def main():
'' 'main method version of the class for the search engine implemented with a balanced tree' ''
b = BalancedBTreeWordFinder(BalancedBTreeWordFinder.askFile(), BalancedBTree())
if __name__ == "__main__":
The error line in class are follow
def __str__(self):
return str(self._val) # here is the error
Complete exestuation of return error are follow
Traceback (most recent call last): File "D:/btree-word-finder-master/btree-word-finder-master/Code_and_texts/", line 20, in <module> BalancedBTreeWordFinder.main() File "D:/btree-word-finder-master/btree-word-finder-master/Code_and_texts/", line 16, in main b.viewIndex() File "D:\btree-word-finder-master\btree-word-finder-master\Code_and_texts\", line 48, in viewIndex self.getBTree().doinOrden() File "D:\btree-word-finder-master\btree-word-finder-master\Code_and_texts\", line 80, in doinOrden self.inOrden(self.getRoot()) File "D:\btree-word-finder-master\btree-word-finder-master\Code_and_texts\", line 89, in inOrden self.visit(probe) # visit mean to search on traversed left File "D:\btree-word-finder-master\btree-word-finder-master\Code_and_texts\", line 107, in visit print(node) File "D:\btree-word-finder-master\btree-word-finder-master\Code_and_texts\", line 39, in __str__ return '%s %s %s'%(self._val) TypeError: __str__ returned non-string (type tuple)

Hope some expert help why return this error where modified by diffrent ways to correct but still i got the same error
The error here in below codes return for me where trying like different return
str(sel._val)  '%s %s %s'%(self._val)
, return '{} {} {}'.format(self._val) and template = '{self._val}'
    return template.format(self)
def __str__(self):
return str(self._val) # here is the error
buran write Apr-12-2021, 01:55 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Thanks @perfringo, @BashBedlam and the problem is solved based on post

Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting "name 'get_weather' is not defined error and no json_data returned? trthskr4 6 351 Sep-14-2021, 09:55 AM
Last Post: trthskr4
  Libraries installed with pipenv, but ModuleNotFoundError returned jpncsu 2 237 Sep-06-2021, 07:24 PM
Last Post: jpncsu
  You have any idea, how fix TypeError: unhashable type: 'list' lsepolis123 2 699 Jun-02-2021, 07:55 AM
Last Post: supuflounder
  TypeError: int() argument must be a string, a bytes-like object or a number, not 'Non Anldra12 2 1,320 May-02-2021, 03:45 PM
Last Post: Anldra12
  What type of *data* is the name of a list/tuple/dict, etc? alloydog 9 1,119 Jan-30-2021, 07:11 AM
Last Post: alloydog
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 871 Nov-04-2020, 11:26 AM
Last Post: Aggam
  TypeError: string indices must be integers hendern 2 1,036 Oct-02-2020, 10:16 PM
Last Post: hendern
  TypeError: 'type' object is not subscriptable Stef 1 1,512 Aug-28-2020, 03:01 PM
Last Post: Gribouillis
  Python Error- TypeError: ('Params must be in a list, tuple, or Row', 'HY000') DarkCoder2020 3 1,899 Jul-29-2020, 12:02 AM
Last Post: Larz60+
  Turn coordinates in string into a tuple Kolterdyx 3 773 Jun-10-2020, 05:04 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020