pyxx.arrays.TypedListWithID#
- class pyxx.arrays.TypedListWithID(*values: T, list_type: Type[T], print_multiline: bool = True, multiline_padding: int = 1)#
Bases:
TypedList[T]A list whose elements must be of a specific type, where each class instance is given a unique identifier
This class modifies the
TypedListclass, assigning a unique identification number to each class instance. This can be useful in tasks such as creating unique class instance names.Notes
The identification number is shared by all instances of the
TypedListWithIDclass and inherited classes. To reset the identifier for an inherited class, simply override the_iditerator by defining_id = itertools.count(0)as a class variable for the subclass.Methods
Inherited Methods
append(value)S.append(value) -- append value to the end of the sequence
clear()count(value)extend(values)S.extend(iterable) -- extend sequence by appending elements from the iterable
index(value, [start, [stop]])Raises ValueError if the value is not present.
insert(index, value)Inserts a value at a given index in the list
pop([index])Raise IndexError if list is empty or index is out of range.
remove(value)S.remove(value) -- remove first occurrence of value.
reverse()S.reverse() -- reverse IN PLACE
Attributes
A unique class instance identification number
Inherited Attributes
The required type of all items in the list
The number of spaces on either side of the list of items in the list when displaying the list's string representation in multiline format
Whether to display the object's string representation in multiline format
- append(value)#
S.append(value) – append value to the end of the sequence
- clear() None -- remove all items from S#
- count(value) integer -- return number of occurrences of value#
- extend(values)#
S.extend(iterable) – extend sequence by appending elements from the iterable
- index(value[, start[, stop]]) integer -- return first index of value.#
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- insert(index: int, value: T)#
Inserts a value at a given index in the list
- property list_type: Type[T]#
The required type of all items in the list
- property multiline_padding: int#
The number of spaces on either side of the list of items in the list when displaying the list’s string representation in multiline format
- pop([index]) item -- remove and return item at index (default last).#
Raise IndexError if list is empty or index is out of range.
- property print_multiline: bool#
Whether to display the object’s string representation in multiline format
- remove(value)#
S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.
- reverse()#
S.reverse() – reverse IN PLACE
- __init__(*values: T, list_type: Type[T], print_multiline: bool = True, multiline_padding: int = 1) None#
Creates a
TypedListlist instanceCreates an instance of the
TypedListobject. This list functions nearly identically to Python’s built-inlist, but it requires that all items in the list be of a user-specified type.- Parameters:
*values (T) – Items to add to the list when initializing the list
list_type (Type[T]) – The required type of all items in the list
print_multiline (bool, optional) – Whether to return a printable string representation of the list in multiline format (default is
False). Multiline format places each item in the list on its own linemultiline_padding (int, optional) – The amount of horizontal padding to place between brackets and list items when creating a printable string representation in multiline format (default is
1). Only applicable ifprint_multilineisTrue
- property id: int#
A unique class instance identification number