knit_graphs.Course module

Course representation of a section of knitting with no parent loops.

This module contains the Course class which represents a horizontal row of loops in a knitting pattern.

class Course(knit_graph)[source]

Bases: object

Course object for organizing loops into knitting rows.

A Course represents a horizontal row of loops in a knitting pattern. It maintains an ordered list of loops and provides methods for analyzing the structure and relationships between courses in the knitted fabric.

Parameters:

knit_graph (Knit_Graph)

__init__(knit_graph)[source]

Initialize an empty course associated with a knit graph.

Parameters:

knit_graph (Knit_Graph) – The knit graph that this course belongs to.

property loops_in_order: list[Loop]

Returns: list[Loop]: The list of loops in this course.

property knit_graph: Knit_Graph

Returns: Knit_Graph: The knit graph that this course belongs to.

add_loop(loop, index=None)[source]

Add a loop to the course at the specified index or at the end.

Parameters:
  • loop (Loop) – The loop to add to this course.

  • index (int | None, optional) – The index position to insert the loop at. If None, appends to the end.

Return type:

None

has_increase()[source]

Check if this course contains any yarn overs that start new wales.

Returns:

True if the course has at least one yarn over (loop with no parent loops) to start new wales.

Return type:

bool

has_decrease()[source]

Check if this course contains any decrease stitches that merge wales.

Returns:

True if the course has at least one decrease stitch (loop with multiple parent loops) merging two or more wales.

Return type:

bool

__getitem__(index)[source]

Get loop(s) at the specified index or slice.

Parameters:

index (int | slice) – The index or slice to retrieve from the course.

Returns:

The loop at the specified index, or list of loops for a slice.

Return type:

Loop | list[Loop]

in_round_with(next_course)[source]

Check if the next course connects to this course in a circular pattern.

This method determines if the courses are connected in the round (circular knitting) by checking if the next course starts at the beginning of this course.

Parameters:

next_course (Course) – The course that should follow this course in circular knitting.

Returns:

True if the next course starts at the beginning of this course, indicating circular knitting.

Return type:

bool

in_row_with(next_course)[source]

Check if the next course connects to this course in a flat/row pattern.

This method determines if the courses are connected in flat knitting (back and forth) by checking if the next course starts at the end of this course.

Parameters:

next_course (Course) – The course that should follow this course in flat knitting.

Returns:

True if the next course starts at the end of this course, indicating flat/row knitting.

Return type:

bool

__contains__(loop)[source]

Check if a loop is contained in this course.

Parameters:

loop (Loop) – The loop to check for membership in this course.

Returns:

True if the loop is in this course, False otherwise.

Return type:

bool

__iter__()[source]

Iterate over loops in this course in order.

Returns:

An iterator over the loops in this course in their natural order.

Return type:

Iterator[Loop]

__reversed__()[source]

Iterate over loops in this course in reverse order.

Returns:

An iterator over the loops in this course in reverse order.

Return type:

Iterator[Loop]

__len__()[source]

Get the number of loops in this course.

Returns:

The total number of loops in this course.

Return type:

int

__str__()[source]

Get string representation of this course.

Returns:

String representation showing the ordered list of loops.

Return type:

str

__repr__()[source]

Get string representation of this course for debugging.

Returns:

String representation showing the ordered list of loops.

Return type:

str