A simple Python script to analyze code files for lines, comments, and function metrics
A beginner-friendly Python tool to analyze .py
files.
- Counts total lines of code
- Counts number of comment lines
- Detects functions
- Calculates comment-to-code ratio
- Finds the longest function by line count
python analyzer.py sample_code.py
Analyzing: sample_code.py
Total lines: 12
Comment lines: 2
Number of functions: 2
Code to comment ratio: 16.67%
Longest function: long_function (6 lines)