Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Parse comments from various source files.

Project Description

# Comment Parser

Python module used to extract comments from source code files of various types. ## Installation — ### Linux/Unix To install run ‘sudo pip3 install comment_parser’. ### OSX and Windows Complete the special installation requirements for python-magic. ## Usage — To use, simply run:

>>> from comment_parser import comment_parser
>>> comment_parser.extract_comments('/path/to/source_file')  # Returns a list of comment_parser.parsers.common.Comments

### extract_comments Signature

def extract_comments(filename, mime=None):
    """Extracts and returns the comments from the given source file.

        filename: String name of the file to extract comments from.
        mime: Optional MIME type for file (str). Note some MIME types accepted
            don't comply with RFC2045. If not given, an attempt to deduce the
            MIME type will occur.
        Python list of parsers.common.Comment in the order that they appear in
            the source file.
        UnsupportedError: If filename is of an unsupported MIME type.

### Comments Interface

class Comment(object):
    """Represents comments found in source files."""
    def text(self):
        """Returns the comment's text.

    def line_number(self):
        """Returns the line number the comment was found on.

    def is_multiline(self):
        """Returns whether this comment was a multiline comment.
            True if comment was a multiline comment, False if not.

    def __str__(self):

    def __eq__(self, other):

## Supported Programming Languages

  1. C
  2. C++
  3. Go
  4. Java
  5. Javascript
  6. Shell scripts (Bash, sh, etc.)
  7. More to come!

Check for corresponding MIME types.

Release History

Release History

This version
History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
comment_parser-1.0.3.tar.gz (4.8 kB) Copy SHA256 Checksum SHA256 Source Sep 6, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting