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 TypedList class, 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 TypedListWithID class and inherited classes. To reset the identifier for an inherited class, simply override the _id iterator by defining _id = itertools.count(0) as a class variable for the subclass.

Methods

__init__(*values, list_type[, ...])

Creates a TypedList list instance

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

id

A unique class instance identification number

Inherited Attributes

list_type

The required type of all items in the list

multiline_padding

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

print_multiline

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 TypedList list instance

Creates an instance of the TypedList object. This list functions nearly identically to Python’s built-in list, 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 line

  • multiline_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 if print_multiline is True

property id: int#

A unique class instance identification number