clean up triple quotes
Project description
triple-quote-clean
TripleQuoteCleaner is a Python class that can be used to clean triple-quoted strings in a variety of ways. It's designed to be used in cases where you want to remove extraneous whitespace and/or add indentation to a triple-quoted string. This is useful when dealing with extensions/code that require some extraneous metadata in the string.
To use TripleQuoteCleaner, simply import it into your Python script:
from triple_quote_clean import TripleQuoteCleaner
Usage
Basic Usage
TripleQuoteCleaner is designed to be used with the >>
, <<
, <
>
, **
operators in Python. All the different operators were selected to allow for
flexibility when considering the operator order, i.e. **
takes the highest
priority and should be used when adding strings
Here's an example:
query = """--sql
select *
from some_database
"""
tqc = TripleQuoteCleaner()
tqc.skip_top_lines = 1
output = query >> tqc
In this example, the >> operator is used to "pipe" the query string into tqc. skip_top_lines is set to 1 so that the first line of the query (the "--sql" line) is skipped. The output of this code will be:
select *
from some_database
Indentation
TripleQuoteCleaner can also be used to add indentation to a triple-quoted string. Here's an example:
input_string = """hello world"""
tqc = TripleQuoteCleaner()
output = '\n' + input_string >> tqc.tab
In this example, tqc.tab is used to add one level of indentation to the output string. The output of this code will be:
hello world
Guide Characters
Indentation can also be specified using a "guide character". This is useful if you want to maintain a certain level of tabs in all your paragraphs in your triple-quoted string. Here's an example:
query = """--sql
$$
select *
from some_database
"""
tqc = TripleQuoteCleaner()
tqc.skip_top_lines = 1
output = query >> tqc
In this example, tqc.guide_character is set to "$$" so that the 4 beginning spaces will be maintained . The output of this code will be:
select *
from some_database
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for triple_quote_clean-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7fb5da8e36aa2dd243694818e54b5edc560bbed5aca4620eb5e393fcd16f1cc |
|
MD5 | b4d63d5a6c49339c54f99b5c89848cb0 |
|
BLAKE2b-256 | 1b91cd7e5e2f9ca1ba15ed700d896768d84c7c4d5716be4260cb7c9eccdca7c9 |