Skip to main content

A Python package for easier multiline string formatting

Project description

Multipyline

Multipyline is a Python library for formatting multiline strings, especially useful for maintaining proper indentation in complex string compositions.

Installation

pip install multipyline

Usage

Using multipyline

multipyline_inner is used inside multipyline f-strings to format inner multiline content, applying a specified prefix to each line.

from multipyline import multipyline, multipyline_inner

inner_text = '''
    Inner line 1
        Offset inner line 2
    Inner line 3
'''

result = multipyline(f'''
    Outer line 1:
        {multipyline_inner(inner_text, " " * 8)}

        > Outer line 2:
        >
        {multipyline_inner(inner_text, " " * 8 + "> ")}
''')

print(result)

The output will be:

Outer line 1:
    Inner line 1
        Offset inner line 2
    Inner line 3

    > Outer line 2:
    >
    > Inner line 1
    >     Offset inner line 2
    > Inner line 3

Using multipyline_format

multipyline_format formats a multiline string with placeholders ({}) which are themselves multiline strings, handling proper indentation for each.

from multipyline import multipyline_format

func_impl = '''
    # Inner part
    if (x > 0):
        print('Another line')
'''

result = multipyline_format(
    '''
    def fun(x: int):
        print('Outer part')
        {}
    ''',
    func_impl,
)

print(result)

The output will be:

def fun(x: int):
    print('Outer part')
    # Inner part
    if (x > 0):
        print('Another line')

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

multipyline-0.1.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

multipyline-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file multipyline-0.1.0.tar.gz.

File metadata

  • Download URL: multipyline-0.1.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.20

File hashes

Hashes for multipyline-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cd177fede4636712de37440080ed5189b47f967dee9c2a7ee8b78b1d25a9e08d
MD5 3a5a779a1f95fbf23c93d1b6a6c44592
BLAKE2b-256 5c3aa91d8fa5f062f0709c862c10118220566a2132e210b2389cf50cf80dd602

See more details on using hashes here.

File details

Details for the file multipyline-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for multipyline-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 775767b01a59d7a894ce5327514ded6b5a48aa3d907c92abdf7e60798aedbab8
MD5 ac92a5d63b963ce7fa9b4e7ab9cf9804
BLAKE2b-256 55b982a474527de7f072d532fba4cb94c8b68d7096adf1334b3d3e69a8e4ac76

See more details on using hashes here.

Supported by

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