Skip to main content

python-loc-counter

The python-loc-counter module was built to count various LOC metrics:

  • source_loc (Everything thats not a comment or blank line)
  • single_comment_loc (Comments with the pound key)
  • single_docstring_loc (Docstrings with single quotes)
  • double_docstring_loc (Docstrings with double quotes)
  • total_comments_loc (single_comment_loc + single_docstring_loc + double_docstring_loc)
  • blank_loc (Any whitespace designated only with string.whitespace)
  • total_line_count (Typical line count)

This uses extensive regex to try to cover weird edge cases, like comments in the middle of a src line (I recommend a quick review about how comments are decidely handled in tests/randomFile.txt). This is written entirely in python with no dependencies outside the standard library. Made to be used as a library.

Installation

This package is locted on github and pypi. If you have pip installed the easiest way to install is:

$ pip install python-loc-counter

Example Usage

from python_loc_counter import LOCCounter

def main():
    counter = LOCCounter(<file_name>)
    loc_data = counter.getLOC()
    print(loc_data)

This will print a dictionary that might look something like:

{
    total_src_loc:1757
    total_single_comments_loc:75
    total_single_docstrings_loc:0
    total_double_docstrings_loc:179
    total_blank_loc:516
    total_comments_loc:254
    total_line_count:2530
}

Development

See a feature or found a bug? Feel free to make suggestions or (better yet) contributions for future iterations!

Example Projects

Metadata

Release files for python-loc-counter 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-loc-counter 0.2
File Size Uploaded
python_loc_counter-0.2.tar.gz 3.8 kB Details

Release files / python_loc_counter-0.2.tar.gz

Download URL python_loc_counter-0.2.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
04d5b1e3998f5a1d3006d279b1bf1d12842631d73fe282cdd8da93e5a5f8950b
BLAKE2b-256 checksum
How to use checksums
937c5dc2139a46728353d76a1f9044c197e1594713228723f8767017060b0f7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page