TypeError: __str__ returned non-string (type tuple) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: TypeError: __str__ returned non-string (type tuple) (/thread-33277.html) |
TypeError: __str__ returned non-string (type tuple) - Anldra12 - Apr-12-2021 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) @staticmethod def main(): '' 'main method version of the class for the search engine implemented with a balanced tree' '' b = BalancedBTreeWordFinder(BalancedBTreeWordFinder.askFile(), BalancedBTree()) b.findOcurrencesInFile('dictionary.txt') b.viewIndex() b.showDepth() if __name__ == "__main__": BalancedBTreeWordFinder.main()The error line in class are follow def __str__(self): return str(self._val) # here is the errorComplete exestuation of return error are follow
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 RE: TypeError: __str__ returned non-string (type tuple) - Anldra12 - Apr-13-2021 Thanks @perfringo, @BashBedlam and the problem is solved based on post https://python-forum.io/Thread-AttributeError-tuple-object-has-no-attribute-format |