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) –
- __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) –
- __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 “;”.
- 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:
- 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:
- static from_str(value, sep=';')[source]
Create a StrList from a string.
- Return type:
- Parameters:
value (str) –
sep (str) –
- 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")
- 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:
- remove(value)[source]
Remove a string from the list
- Parameters:
value (str) – String to remove.
- Returns:
Self.
- Return type:
- 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