Class StrList

class ooodev.utils.string.str_list.StrList(strings=None, sep=';')[source]

Bases: object

String List Class.

New in version 0.41.0.

Parameters:
  • strings (Iterable[str] | None) –

  • sep (str) –

__add__(other)[source]

Add two lists.

Return type:

StrList

Parameters:

other (StrList) –

__contains__(value)[source]

Get if the value is in the list.

Parameters:

value (str) –

__eq__(other)[source]

Check if two lists are equal.

Return type:

bool

Parameters:

other (StrList) –

__getitem__(index: int) str[source]
__getitem__(index: slice) ooodev.utils.string.str_list.StrList
__getitem__(index)

Get an item from the list.

Supports slicing. When sliced a new StrList is returned.

Return type:

Any

Parameters:

index (int | slice) –

__iadd__(other)[source]

Add two lists.

Return type:

StrList

Parameters:

other (StrList) –

__init__(strings=None, sep=';')[source]

Constructor

Parameters:
  • strings (Iterable[str], optional) – Iterable String such as a list or a tuple. If a str in passed int the each char become an item. Defaults to None.

  • sep (str, optional) – _description_. Defaults to “;”.

__len__()[source]

Get the length of the list.

__reversed__()[source]

Reverse iterator for the list.

append(value='', no_indent=False)[source]

Add a string to the list

Parameters:
  • value (str, optional) – String to add. Defaults to “”.

  • no_indent (bool, optional) – If True, no indent is added. Defaults to False.

Returns:

Self.

Return type:

StrList

clear()[source]

Clear the list.

Return type:

StrList

copy()[source]

Copy the list.

Return type:

StrList

count(value)[source]

Get the count of a value.

Return type:

int

Parameters:

value (str) –

decrease_indent()[source]

Decrease the indent.

Return type:

StrList

extend(strings, no_indent=False)[source]

Extend the list.

Parameters:
  • strings (Iterable[str]) – Strings to add.

  • no_indent (bool, optional) – If True, no indent is added. Defaults to False.

Return type:

StrList

static from_str(value, sep=';')[source]

Create a StrList from a string.

Return type:

StrList

Parameters:
  • value (str) –

  • sep (str) –

increase_indent()[source]

Increase the indent.

Return type:

StrList

indented()[source]

Context Manager. Increase the indent.

Example

code = StrList(sep="\n")
code.append("Sub Main")
with code.indented():
    code.append('MsgBox "Hello World"')
code.append("End Sub")
index(value)[source]

Get the index of a value.

Return type:

int

Parameters:

value (str) –

insert(index, value, no_indent=False)[source]

Insert a value into the list.

Parameters:
  • index (int) – Index to insert the value.

  • value (str) – Value to insert.

  • no_indent (bool, optional) – If True, no indent is added. Defaults to False.

Return type:

StrList

pop(index)[source]

Pop a value from the list.

Return type:

str

Parameters:

index (int) –

remove(value)[source]

Remove a string from the list

Parameters:

value (str) – String to remove.

Returns:

Self.

Return type:

StrList

remove_duplicates()[source]

Remove duplicates from the list.

Return type:

StrList

reverse()[source]

Reverse the list.

Return type:

StrList

set_indent(value)[source]

Set the indent.

Return type:

StrList

Parameters:

value (int) –

sort(key=None, reverse=False)[source]

Sort the list.

Return type:

StrList

to_string()[source]

Convert list to string.

Return type:

str

property indent_amt: int

Get/Sets the indent amount

Return type:

int

property indent_str: str

Gets/Sets the indent string

Return type:

str

property separator: str

Gets/Sets the separator.

Return type:

str