import ast
python_source = ""
try:
with open("python_source.py", 'r') as f:
python_source = f.read()
except:
print("Failed to read source code of python_source.py. Exiting.")
exit()
if python_source == "":
print("The source code of python_source.py read in is empty. Exiting.")
exit()
parsed_source = ast.parse(python_source)
classes = [node.name for node in ast.walk(parsed_source) if isinstance(node, ast.ClassDef)]
display the class names within a python source file 展示python源码中的所有类名
最新推荐文章于 2024-08-10 10:46:00 发布