Skip to main content

Trivial split for strings with quotes and escaped characters

Project description

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, quote='"\'', quote_keep=False, delimiter=':;,', escape='/^', trim='', remark='#'):
    """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

from tssplit 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

Project details


Download files

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

Source Distribution

tssplit-1.0.8.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

tssplit-1.0.8-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file tssplit-1.0.8.tar.gz.

File metadata

  • Download URL: tssplit-1.0.8.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for tssplit-1.0.8.tar.gz
Algorithm Hash digest
SHA256 364ba476631f613690a9ce5d1552cf104e650e714d0567e4867452d0a0df266f
MD5 d4843e438205f338995d2e6dd7b2fa98
BLAKE2b-256 7cb4db6e346d9c2efa0d07fe04923615c0ad920d1317d9772f964bd413aa7c39

See more details on using hashes here.

File details

Details for the file tssplit-1.0.8-py3-none-any.whl.

File metadata

  • Download URL: tssplit-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for tssplit-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d7973c2ba1a200b69608d1d57bda7928384c8f818d0942f0265b143767f15221
MD5 65e0654c4e055aa46a59cda729fe3144
BLAKE2b-256 a34306fe1fd0593aa7d018c8f87f1c707b951320932025d41fcdea8a8aebb69f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page