Skip to main content

k3fmt

Action-CI Documentation Status Package

It provides with several string operation functions.

k3fmt is a component of pykit3 project: a python3 toolkit set.

Name

k3fmt

It provides with several string operation functions.

Status

This library is considered production ready.

Install

pip install k3fmt

Synopsis

import k3fmt

lines = [
    "hello",
    "world",
]

# add left padding to each line in a string
k3fmt.line_pad("\n".join(lines), " " * 4)
# "    hello"
# "    world"


# format a multi-row line
items = [
    "name:",
    ["John", "j is my nick"],
    "age:",
    26,
    "experience:",
    ["2000 THU", "2006 sina", "2010 other"],
]

k3fmt.format_line(items, sep=" | ", aligns="llllll")
# outputs:
#    name: | John         | age: | 26 | experience: | 2000 THU
#          | j is my nick |      |    |             | 2006 sina
#          |              |      |    |             | 2010 other


# ['ab']
print(k3fmt.tokenize("ab"))
# ['a', 'b']
print(k3fmt.tokenize("a b"))
# ['a', 'b']
print(k3fmt.tokenize(" a  b "))
# ['a', 'b']
print(k3fmt.tokenize(" a\t b\n c\r "))
# ['a b', 'c d']
print(k3fmt.tokenize("a bxyc d", sep="xy"))
# ['a', 'x x', 'b']
print(k3fmt.tokenize('a "x x" b'))
# ['a', 'x x', 'b']
print(k3fmt.tokenize("a 'x x' b 'x"))  # the last `'x` has no pair, discard
# ['a', 'a b', 'c d']
print(k3fmt.tokenize(" a  xa bx yc dy ", quote="xy"))
# ['a', 'xa bx', 'yc dy']
print(k3fmt.tokenize("a xa bx yc dy", quote="xy", preserve=True))
# ['', 'a', 'xa bx', 'yc dy', '']
print(k3fmt.tokenize(" a xa bx yc dy ", sep=" ", quote="xy", preserve=True))

Author

Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Copyright and License

The MIT License (MIT)

Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Metadata

Release files for k3fmt 0.1.7

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

Source distribution (sdist)

Source distribution for k3fmt 0.1.7
File Size Uploaded
k3fmt-0.1.7.tar.gz 12.0 kB Details

Built distribution (wheel)

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

Total release size: 21.2 kB

Release files / k3fmt-0.1.7.tar.gz

Download URL k3fmt-0.1.7.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
921bed5feda9c22c06c5f1189086f039c370c289c656a552c2fc6b9dcafc645f
BLAKE2b-256 checksum
How to use checksums
6c3bbe86664bbaf3b96fedb333463453e5a9364aafbf355314b7ab332b059596
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / k3fmt-0.1.7-py3-none-any.whl

Download URL k3fmt-0.1.7-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9e8b6a87a44e61d1feb281df003a1d63abfbf0f538d5b61ba93d1d33b00f0bb
BLAKE2b-256 checksum
How to use checksums
ffc93de7e8ee5be4e11f7e2c355917351f2899db23b01a5ce1eb23854e70793b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release history Release notifications | RSS feed

0.1.8

2 release files

This release

0.1.7 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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