I am learning inheritance and wrote a simple function to visualize subclasses, here is the code:
def PrintClassTree(thisclass, nest=0):
if nest > 1:
print(' |' * (nest - 1), end='')
if nest > 0:
print(' +---', end='')
print(thisclass.__name__)
for subclass in thisclass.__subclasses__():
PrintClassTree(subclass, nest+1)
PrintClassTree(dict)
when I ran the function I got
dict
+---OrderedDict
+---defaultdict
+---Counter
This is different from directly calling dict.__subclasses__(). When I ran in debugging mode, I got the following list, the same as calling dict.__subclasses__()
dict
+---OrderedDict
+---defaultdict
| +---Quoter
+---Counter
+---_EnumDict
+---_QByteMap
+---StgDict
+---_ReqExtras
+---ZipManifests
| +---MemoizedZipManifests
+---TypedDict
I tried list and again, I can only get a full list of subclasses in debugging mode. I feel I am missing something here, but what makes debugging different from running the function?
I use Pycharm so both were done in the same IDLE. I couldn't find anything on this behavior. I tried BaseException and this seems to give me correct results when running the function.