Question: This might be a two part question. First is the context if better alternatives can be suggested. Second part is the (probably) XY problem for my solution. xy - Have a method in the class which returns a list of all functions in the class in order they were written/typed. My projects typically involve long sequences of queries/data transformations. I want to be able to wrap each step as a function so that the docstrings can be discoverable by those tools. But don't want to have to retype every function call at the end of each notebook. Undesirable way: def print_something_else(): """ Some docstring here """ print("something else") def print_some_other_thing(): """ Some other docstring here """ print("something other thing") def print_something(): print("something") print_something_else() print_some_other_thing() print_something()  I would like to just define the functions and have some wrapper so that they are run in order. Attempt: class RegisteredCommandSequence: def __init__(self): def __include(method): only_include_if = [ type(getattr(self, method)).__name__ == 'method', not(method.startswith('__')), method not in ('run_all', 'run_from_to')] return all(only_include_if) self._public_nonbuiltin_callable_methods = [ method for method in dir(self) if __include(method)] def run_all(self): for func in self._public_nonbuiltin_callable_methods: getattr(self, func)() class QueryBundle(RegisteredCommandSequence): def __init__(self): super().__init__() def print_something_else(self): """ Some docstring here """ print("something else") def print_some_other_thing(self): """ Some other docstring here """ print("something other thing") def print_something(self): print("something") test = QueryBundle() test.run_all()  something other thing something something else  The problem is the dir() doesn't preserve the order in which the functions were written, which is vital. If in the class itself I have a list of all the in-scope methods, it'd be very convenient to be able to run subsequences like test.run_from_to('print_something_else', 'print_some_other_thing'). Things I've considered  Decorators which dictate the order of execution of each. Using the classes __dict__, which seems to preserve the order, but is empty when defined how I'm trying to use it.  example: class ShowEmptyDict: def __init__(self): self.print_methods_in_class() def print_methods_in_class(self): return(self.__dict__) demo = ShowEmptyDict() if demo.print_methods_in_class(): print('Not empty') else: print('empty') 

Answer: I would advise against source code order dictating execution order, but if you really need to, you can use inspect.getsourcelines() to get the line number where an object starts at. import inspect class Funcs: def func_8(self): pass def func_5(self): pass def func_4(self): pass instance = Funcs() funcs = [getattr(instance, func) for func in dir(instance) if inspect.ismethod(getattr(instance, func))] funcs.sort(key=lambda func: inspect.getsourcelines(func)[1]) print(funcs)  prints out [ <bound method Funcs.func_8 of <__main__.Funcs object at 0x1175b0740>>, <bound method Funcs.func_5 of <__main__.Funcs object at 0x1175b0740>>, <bound method Funcs.func_4 of <__main__.Funcs object at 0x1175b0740>>, ]  This generalizes to any namespace where you have functions, of course, not just a class instance.