提取代码如下
import tokenize import re with tokenize.open('readcomment.py') as f: list = [] for toktype, tok, start, end, line in tokenize.generate_tokens(f.readline): if toktype == tokenize.COMMENT: if re.search(r'Author:(.+)', tok): a = re.findall(r'Author:(.+)', tok)[0].replace(" ","") print(a) list.append(a) print(list)
例如源码如下
def say_hello(): # Author:吴彦祖 """ 注册api_lib.application.core下的所有业务接口类到register :return: """ print("Hello, World!") # Author: 刘亦菲 if __name__ == '__main__': # 这里是main say_hello()
执行结果
吴彦祖
刘亦菲
['吴彦祖', '刘亦菲']
标签:__,刘亦菲,Author,化器,python,源码,tokenize,吴彦祖 From: https://www.cnblogs.com/healerwu/p/16896478.html