Feb-09-2021, 07:44 AM
(Feb-09-2021, 06:42 AM)buran Wrote: So, what have you tried? Because, what's the point if you don't try for yourself.i have done few things e.g.
try to sort the subclass first by sorting the for loop as follow
for subclass in sorted(thisclass.__subclasses__()):, but it cant work because the sorted() only work on string or number type
then i try to create a list that will consist of the subclass name that already converted to "string" type, so next i can sort that list, then print it, so i try this code
def printExcTree(thisclass, nest = 0): if nest > 1: print(" |" * (nest - 1), end="") if nest > 0: print(" +---", end="") print(thisclass.__name__) a = [] for subclass in thisclass.__subclasses__(): a.append(subclass.__name__) for srt_subclass in a : printExcTree(srt_subclass, nest + 1) printExcTree(BaseException)and cant work because when it comes to recursion
printExcTree(srt_subclass, nest + 1)the first parameter pass a str type, meanwhile the
print(thisclass.__name__)only can work on class type. Is there any way to change the str type becoming a class type e.g. ValueError become "ValueError" then i can change it again "valueError" become ValueError