Skip to main content

Trivial split for strings with multiple character delimiters, quotes and escaped characters

Downloads Buy Me A Coffee

Installation

pip install tssplit

Usage

Syntax

def tssplit(s:str, quote:str='"\'', quote_keep:bool=False, delimiter:str=':;,', escape:str='/^',
            trim:str='', remark:str='#') -> list[str]:

    """Split a string by delimiters with quotes and escaped characters, optionally trimming results

    :param s: A string to split into chunks
    :param quote: Quote chars to protect a part of s from parsing
    :param quote_keep: Preserve quote characters in the output or not
    :param delimiter: A chunk separator character
    :param escape: An escape character
    :param trim: Trim characters from chunks
    :param remark: Ignore all characters after remark sign
    :return: A list of chunks
    """

Example

import tssplit

tssplit('--:--;--,--"--/--"--\'--:--\'--/"--^--',
        quote='"\'', delimiter=':;,', escape='/^', trim='')
['--', '--', '--', '----/------:----"----']

tssplit('--:--;--,--"--/--"--\'--:--\'--/"--^--',
        quote='"\'', delimiter=':;,', escape='/^', trim='', quote_keep=True)
['--', '--', '--', '--"--/--"--\'--:--\'--"----']

tssplit('--:--;--,--"--/--"--\'--:--\'--# Ignore this',
        quote='"\'', delimiter=':;,', escape='/^', trim='', quote_keep=True, remark='#')
['--', '--', '--', '--"--/--"--\'--:--\'--']

Changelog

  • 2020.03.28 v1.0 Initial release
  • 2020.03.28 v1.0.1 Many quick fixes to make all things work in PyPI
  • 2020.03.29 v1.0.2 Minor fixes, Readme update, Long description provided
  • 2020.03.29 v1.0.3 Trim option to strip() characters from chunks
  • 2020.03.29 v1.0.4 Multiple characters for quotes, delimiters and escapes
  • 2022.02.04 v1.0.5 Added quote_keep option to preserve quote marks in the output or not
  • 2023.01.12 v1.0.6 Remark characters interrupt string parsing
  • 2024.04.03 v1.0.7 Cosmetics to make pylint happy
  • 2024.10.19 v1.0.8 Better module import; minor cosmetic changes
  • 2024.12.25 v1.0.9 Type annotations by @mkupferman + misc minor changes

Metadata

Release files for tssplit 1.0.9

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

Source distribution (sdist)

Source distribution for tssplit 1.0.9
File Size Uploaded
tssplit-1.0.9.tar.gz 3.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tssplit 1.0.9
File Interpreter ABI Platform
tssplit-1.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 7.8 kB

Release files / tssplit-1.0.9.tar.gz

Download URL tssplit-1.0.9.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8e58973e1d69c21fd9b4deeaa757fb6ab8f17b4fa7469387a120f0e99bde8e22
BLAKE2b-256 checksum
How to use checksums
8beace705a18347a87a7a22dba4f0dd100ba1cc6fca0b3ad4b0613461bfcc90b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.21

Release files / tssplit-1.0.9-py3-none-any.whl

Download URL tssplit-1.0.9-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f23f0cb3c7a27c7ed8bb2b3e7ca06606ee268044fc78a20419b9673beb85683
BLAKE2b-256 checksum
How to use checksums
3dd16b624a6e44a299427615dee45fbb19e2f8d3babeaaac78635d2eca4e7370
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.21

Release history Release notifications | RSS feed

This release

1.0.9 This release

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

3 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

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