KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I decided to use str for printing the contents of a tree in tree-like structure,using something like print tree The nodes of the tree are all objects of user-created classes and I overload their __str__ magic method in order to use the child nodes' str after indent t tabs like that def __str__ (self,t=0) :` return t*'\t' + str(self.label) +':' +'\n'+ str(self.l,t+1)+'\n'+str(self.right,t+1)+'\n' However I can't call str with that t parameter,but I can call node.__ str__(t=4) .Isn't str ,only shortcut to the magic method?Or is that because the parser rejects additional params to str without checking the magic method? P.S. I am interested in the behaviour.I know that's not the best way to print a tree,it was a hack ;)
Tags (comma-separated)
Save Edits
Cancel