StringDifferently

class differently.StringDifferently(a: Optional[str], b: Optional[str], color: bool = True)

Visualises the differences between two strings.

Use the string representation or render() to render.

Parameters
  • a – First string

  • b – Second string

  • color – Include or exclude colour formatting (default is True)

Example

from differently import StringDifferently

diff = StringDifferently(
    "borst of times",
    "worst of times",
    color=False,
)
print(diff)
borst of times  ~  worst of times
property a: Optional[str]

Gets the first string.

property arrow: str

Gets the arrow character that describes the difference.

property b: Optional[str]

Gets the second string.

render(lhs_width: int, writer: IO[str]) None

Renders the visualisation to writer.

Parameters
  • lhs_width – Width to pad the left-hand side

  • writer – Writer

Example

from io import StringIO
from differently import StringDifferently

diff = StringDifferently(
    "It was the burst of times.",
    "It was the worst of times.",
    color=False,
)

writer = StringIO()
diff.render(lhs_width=26, writer=writer)
print(writer.getvalue())
It was the burst of times.  ~  It was the worst of times.
property type: differently.difference_type.DifferenceType

Gets the type of the difference.