For the test pedagogical module, I need to check the doctrines in the exact order. Is there a way to capture all callables in the current module in the order they are defined?
What I tried:
Thanks Martijn, I eventually found. This is the complete snippet for Python3.
import sys import inspect def f1(): "f1!" pass def f3(): "f3!" pass def f2(): "f2!" pass funcs = [elt[1] for elt in inspect.getmembers(sys.modules[__name__], inspect.isfunction)] ordered_funcs = sorted(funcs, key=lambda f: f.__code__.co_firstlineno) for f in ordered_funcs: print(f.__doc__)
, , :
import inspect ordered = sorted(inspect.getmembers(moduleobj, inspect.isfunction), key=lambda kv: kv[1].__code__.co_firstlineno)
(name, function). Python 2.5 .func_code .__code__.
(name, function)
.func_code
.__code__
, , ; func.__module__ == moduleobj.__name__ .
func.__module__ == moduleobj.__name__
Source: https://habr.com/ru/post/1523926/More articles:Должен ли я использовать переменные состояния из стандарта С++ или из Windows API? - c++Spring Querying data from a method does not recognize a column - spring-dataError .NET Framework Windows XP, Visual Studio Express - windowsRegular expression pattern not matching input line - c #Need to free the contents of a QList? - c ++What caches of Sitecore affect Caching.ScavengeInterval and how? - cachingSpring data and mongodb - simple rollback with Spring inside @Transactional - javaWhy not the result of this casting? - cUsing Kendo Grid with knockoutjs row template makes filtering impossible - javascriptDynamically enable / disable kendo datepicker using Knockout-Kendo.js - knockout.jsAll Articles