怎么提取一个python文件中所有得函数名称

可以通过创建一个Python脚本来读取一个文件(其中包含函数名称),并将这些函数名称写入另一个文件。以下是一个简单的示例:
假设你有一个名为 mytest.py 的文件,其中包含一些函数:

# mytest.py  
def function1():  
    pass  
  
def function2():  
    pass  
  
def function3():  
    pass

可以创建一个名为 read_functions.py 的脚本来读取 mytest.py 文件中的函数名称,并将它们写入另一个文件:

# read_functions.py  
import inspect  
import mytest
 
with open('function_names.txt', 'w') as f:  
    for name, val in inspect.getmembers(mytest, inspect.isfunction):  
        f.write(name + '\n')

这个脚本使用Python的 inspect 模块来获取 functions 模块中的函数名称,并将它们写入一个名为 function_names.txt 的文件。这个文件中将包含 functions.py 文件中定义的每个函数的名称,每个名称占一行。

你可能感兴趣的:(python,开发语言)