pyleftpad

Python version of left pad.

Install

$ pip install pyleftpad

Usage

There are two way to use pyleftpad. First of all, you can use leftpad() function from leftpad module in your Python script.

from leftpad import leftpad

def main():
    print(leftpad('hello world', 40))


main()

Second of all, you can use directly leftpad command in your shell.

… code-block:: bash

$ leftpad -l 40 “hello world”

leftpad — Python version Left Pad

It is Python version of Javascript library named left pad

leftpad.cli — Left Pad Command Line Interface

pyleftpad provide CLI called leftpad which one can use on your shell.

$ pip install pyleftpad
$ leftpad -n 10 foo
      foo
$ leftpad -n 3 -f 0 7
007
leftpad.cli.arg_parser()

Create argument parser using argparse.ArgumentParser.

leftpad.cli.main()

Main function to be executed by CLI.

leftpad.func — Left Pad functions

Define left pad functions.

leftpad.func.leftpad(source, length, fill_value=None)

String left pad.

>>> leftpad('foo', 5)
'  foo'
>>> leftpad('foobar', 6)
'foobar'
>>> leftpad(1, 2, '0')
'01'
>>> leftpad(17, 5, 0)
'00017'
Parameters:
  • source (str or int) – A string or integer.
  • length (int) – A length of result.
  • fill_value (str or int) – A value that filled in padded space.
Returns:

A padded string.

Return type:

str

Indices and tables