Python Forum
How to Sorted and display the Subclasses of BaseException
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Sorted and display the Subclasses of BaseException
#1
I have a task from the online course that i enrolled free recently Smile , can anyone help me for sorting the printout from the line code as follow :
def printExcTree(thisclass, nest = 0):
    if nest > 1:
        print("   |" * (nest - 1), end="")
    if nest > 0:
        print("   +---", end="")

    print(thisclass.__name__)

    for subclass in thisclass.__subclasses__():
        printExcTree(subclass, nest + 1)

printExcTree(BaseException)
and here is the output :
Output:
BaseException +---Exception | +---TypeError | +---StopAsyncIteration | +---StopIteration | +---ImportError | | +---ModuleNotFoundError | | +---ZipImportError | +---OSError | | +---ConnectionError | | | +---BrokenPipeError | | | +---ConnectionAbortedError | | | +---ConnectionRefusedError | | | +---ConnectionResetError | | +---BlockingIOError | | +---ChildProcessError | | +---FileExistsError | | +---FileNotFoundError | | +---IsADirectoryError | | +---NotADirectoryError | | +---InterruptedError | | +---PermissionError | | +---ProcessLookupError | | +---TimeoutError | | +---UnsupportedOperation | | +---herror | | +---gaierror | | +---timeout | | +---Error | | | +---SameFileError | | +---SpecialFileError | | +---ExecError | | +---ReadError | +---EOFError | +---RuntimeError | | +---RecursionError | | +---NotImplementedError | | +---_DeadlockError | | +---BrokenBarrierError | +---NameError | | +---UnboundLocalError | +---AttributeError | +---SyntaxError | | +---IndentationError | | | +---TabError | +---LookupError | | +---IndexError | | +---KeyError | | +---CodecRegistryError | +---ValueError | | +---UnicodeError | | | +---UnicodeEncodeError | | | +---UnicodeDecodeError | | | +---UnicodeTranslateError | | +---UnsupportedOperation | +---AssertionError | +---ArithmeticError | | +---FloatingPointError | | +---OverflowError | | +---ZeroDivisionError | +---SystemError | | +---CodecRegistryError | +---ReferenceError | +---BufferError | +---MemoryError | +---Warning | | +---UserWarning | | +---DeprecationWarning | | +---PendingDeprecationWarning | | +---SyntaxWarning | | +---RuntimeWarning | | +---FutureWarning | | +---ImportWarning | | +---UnicodeWarning | | +---BytesWarning | | +---ResourceWarning | +---error | +---Verbose | +---Error | +---TokenError | +---StopTokenizing | +---Empty | +---Full | +---_OptionError | +---TclError | +---SubprocessError | | +---CalledProcessError | | +---TimeoutExpired | +---Error | | +---NoSectionError | | +---DuplicateSectionError | | +---DuplicateOptionError | | +---NoOptionError | | +---InterpolationError | | | +---InterpolationMissingOptionError | | | +---InterpolationSyntaxError | | | +---InterpolationDepthError | | +---ParsingError | | | +---MissingSectionHeaderError | +---InvalidConfigType | +---InvalidConfigSet | +---InvalidFgBg | +---InvalidTheme | +---EndOfBlock | +---BdbQuit | +---error | +---_Stop | +---PickleError | | +---PicklingError | | +---UnpicklingError | +---_GiveupOnSendfile | +---error | +---LZMAError | +---RegistryError | +---ErrorDuringImport +---GeneratorExit +---SystemExit +---KeyboardInterrupt
what i want to do is to sort every subclass depend on his first letter alphabetly and the subclass from every subclass follow the same rule...
Reply


Messages In This Thread
How to Sorted and display the Subclasses of BaseException - by Fernando_7obink - Feb-09-2021, 05:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  A function that checks if the list is sorted pooyan89 16 17,963 Apr-22-2024, 09:14 AM
Last Post: DeaD_EyE
  Functions returns content of dictionary as sorted list kyletremblay15 1 2,166 Nov-21-2019, 10:06 PM
Last Post: ichabod801
  defining a function to see if a list is sorted Siylo 14 7,386 Nov-29-2018, 05:25 PM
Last Post: wavic
  sorted list not displaying Crackity 6 5,312 Jul-18-2017, 12:50 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

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