Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to monitor all global functions in Python

Shulou Source: shulou.com Published: 2022-06-02 07:17:17 10月04日 Update

Python how to monitor all the global functions, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

First create a global variable: _ globalized, and then write a function that populates the _ globalized with the function name. At the same time, the @ _ globalize modifier is injected into each function.

_ globalized = ['std_basis']

Def _ globalize (meth):

Name = meth.__name__

_ globalized.append (name)

Return meth

Inject into a global function

@ _ globalize

Def global_fun (a):

Print ('input a:' + str (a))

@ _ globalize

Def global_fun2 (b):

Print ('input b:' + str (b))

test

If _ name__ = = "_ _ main__":

Global_fun (1)

Global_fun2 (2)

Results:

Input a: 1

Input b: 2

Print (_ globalized) # print global function

['std_basis',' global_fun', 'global_fun2']

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Function global help monitoring clarity content variable at the same time name article novice more knowledge result industry information information channel problem demand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi Huawei MariaDB macOS