Home

Awesome

detect-indent for Python Test

Python port of sindresorhus/detect-indent All attribution goes to that project.

Detect the indentation of code

Pass in a string of any kind of text and get the indentation.

Use cases

Install

pip install detect-indent

Usage

from detect_indent import detect_indent

sample_string = '''
Example string
  with an indentation
    of two spaces
'''

indent = detect_indent(sample_string)
print(indent)  # {'amount': 2, 'type': 'space', 'indent': '  '}

API

Returns a dictionary with the following stats about indentation:

Algorithm

The current algorithm looks for the most common difference between two consecutive non-empty lines. More Details