Go through a number of functions in Python -


I have an unknown number in Python script (well, it is known, but not static) which is site_ .. I was thinking that some of these functions are a way of going into the main function which calls them. If something like:

  foreach function_that_has_site_ as coolfunc if coolfunc (blabla, yada) == true: return coolfunc (blabla, yada)  

this << p>

code> inspect The module, which is already mentioned in other answers, is especially easy because you can easily get the filter the name and value of the items about which you care about two Argument: The object whose member you lost , And predicate (a function returned bool ) that will accept (return is true ) only items that you have about care for.

To obtain "this module" object you need the following famous phrases:

  import syses_modules = sys.modules [__name__]  

In your predominance, you only want to select objects that are functions and whose name begins with site_ :

  Check the import function_that_has_site (f): Inspect the return. Difference (F) and F.__ name __. With resultwith ('site_')  

Results with these two: If the result: return

for < Coolfunc (this_module, function_that_has_site): result = coolfunc (blabla, yada) / pre>

I have also divided the loop body so that only once (Which both time saves and is a bit fer approach, avoiding possible side effects) ... and also rewording in Python -;)


Comments