pydicom.multival.MultiValue

class pydicom.multival.MultiValue(type_constructor: Callable[[Any], T], iterable: Iterable[Any])[source]

Class to hold any multi-valued DICOM value, or any list of items that are all of the same type.

This class enforces that any items added to the list are of the correct type, by calling the constructor on any items that are added. Therefore, the constructor must behave nicely if passed an object that is already its type. The constructor should raise TypeError if the item cannot be converted.

Note, however, that DS and IS types can be a blank string '' rather than an instance of their classes.

__init__(type_constructor: Callable[[Any], T], iterable: Iterable[Any]) None[source]

Create a new MultiValue from an iterable and ensure each item in the MultiValue has the same type.

Parameters:
  • type_constructor (callable) – A constructor for the required type for all items. Could be the class, or a factory function. Takes a single parameter and returns the input as the desired type (or raises an appropriate exception).

  • iterable (iterable) – An iterable (e.g. list, tuple) of items to initialize the MultiValue list. Each item in the iterable is passed to type_constructor and the returned value added to the MultiValue.

Methods

__init__(type_constructor, iterable)

Create a new MultiValue from an iterable and ensure each item in the MultiValue has the same type.

append(item)

Append an item.

clear()

count(value)

extend(val)

Extend using an iterable containing the same types of item.

index(value, [start, [stop]])

Raises ValueError if the value is not present.

insert(position, item)

Insert an item at position.

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

sort(*args, **kwargs)

append(item: T) None[source]

Append an item.

clear() None -- remove all items from S[source]
count(value) integer -- return number of occurrences of value[source]
extend(val: Iterable[T]) None[source]

Extend using an iterable containing the same types of item.

index(value[, start[, stop]]) integer -- return first index of value.[source]

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

insert(position: int, item: T) None[source]

Insert an item at position.

pop([index]) item -- remove and return item at index (default last).[source]

Raise IndexError if list is empty or index is out of range.

remove(value)[source]

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

reverse()[source]

S.reverse() – reverse IN PLACE