IdCollection Module

See this module if you like to store object s that have an id attribute.

class knittingpattern.IdCollection.IdCollection[source]

Bases: object

This is a collections of object that have an id attribute.

Returns:whether there is anything in the collection.
Return type:bool

Get the object with the id

ic = IdCollection()
assert ic[] == object_1
assert ic[] == object_1
Parameters:id_ – the id of an object
Returns:the object with the id
Raises:KeyError – if no object with id was found

Create a new IdCollection with no arguments.

You can add objects later using the method append().


allows you to iterate and use for-loops

The objects in the iterator have the order in which they were appended.

Returns:the number of objects in this collection

list of weak references to the object (if defined)


Add an object to the end of the IdCollection.

Parameters:item – an object that has an id

Get the object at an index.

Parameters:index (int) – the index of the object
Returns:the object at index

The first element in this collection.

Returns:the first element in this collection
Raises:IndexError – if this collection is empty