Mesh Module

This module contains the meshes of the knit work.

class knittingpattern.Mesh.Mesh[source]

Bases: object

A mesh that is either consumed or produced by an instruction.

assert mesh.is_produced() or mesh.is_consumed()

Since this is an abstract base class you will only get instances of ProducedMesh and ConsumedMesh.

__repr__()[source]

This mesh as string.

Returns:the string representation of this mesh.
Return type:str

This is useful for print() and class:str

__weakref__

list of weak references to the object (if defined)

as_consumed_mesh()[source]

The consumed part to this mesh.

as_produced_mesh()[source]

The produced part to this mesh.

If meshes are split up, it may be important which row the mesh is connected to afterwards. This method returns the mesh that is connected to the producing row.

If you got this mesh from InstructionInRow.produced_meshes or Row.produced_meshes, this returns the same object.

See also

as_consumed_mesh(), knittinpattern.Instruction.InstructionInRow.produced_meshes, knittinpattern.Row.Row.produced_meshes

can_connect_to(other)[source]

Whether a connection can be established between those two meshes.

connect_to(other_mesh)[source]

Create a connection to an other mesh.

Warning

Both meshes need to be disconnected and one needs to be a consumed and the other a produced mesh. You can check if a connection is possible using can_connect_to().

consuming_instruction

Instruction which consumes this mesh.

Returns:the instruction that consumes this mesh
Return type:knittingpattern.Instruction.InstructionInRow

Warning

Check with is_consumed() before!

consuming_row

Row which consumes this mesh.

Returns:the row that consumes this mesh
Return type:knittingpattern.Row.Row

Warning

Check with is_consumed() before!

disconnect()[source]

Remove the connection between two rows through this mesh.

After disconnecting this mesh, it can be connected anew.

index_in_consuming_instruction

Index in instruction as consumed mesh.

Returns:the index of the mesh in the list of meshes that consuming_instruction consumes
Return type:int
instruction = mesh.consuming_instruction
index = mesh.index_in_consuming_instruction
assert instruction.consumed_meshes[index] == mesh

Warning

Check with is_consumed() before!

index_in_consuming_row

Index in row as consumed mesh.

Returns:the index of the mesh in the list of meshes that consuming_row consumes
Return type:int
row = mesh.consuming_row
index = mesh.index_in_consuming_row
assert row.consumed_meshes[index] == mesh

Warning

Check with is_consumed() before!

index_in_producing_instruction

Index in instruction as a produced mesh.

Returns:the index of the mesh in the list of meshes that producing_instruction produces
Return type:int
instruction = mesh.producing_instruction
index = mesh.index_in_producing_instruction
assert instruction.produced_meshes[index] == mesh

Warning

Check with is_produced() before!

index_in_producing_row

Index in row as produced mesh.

Returns:the index of the mesh in the producing_row
Return type:int
row = mesh.producing_row
index = mesh.index_in_producing_row
assert row[index] == mesh

Warning

Check with is_produced() before!

is_connected()[source]

Returns whether this mesh is already connected.

Returns:whether this mesh is connected to an other.
Return type:bool
is_connected_to(other_mesh)[source]

Whether the one mesh is conencted to the other.

is_consumed()[source]

Whether the mesh has an instruction that consumed it.

Returns:whether the mesh is consumed by an instruction
Return type:bool

If you get this mesh from knittingpattern.Instruction.InstructionInRow.consumed_meshes or knittingpattern.Row.Row.consumed_meshes, this should be True.

Warning

Before you use any methods on how the mesh is consumed, you should check with mesh.is_consumed().

is_knit()[source]

Whether the mesh is produced by a knit instruction.

Returns:whether the mesh is knit by an instruction
Return type:bool
is_mesh()[source]

Whether this object is a mesh.

Returns:True
Return type:bool
is_produced()[source]

Whether the mesh has an instruction that produces it.

Returns:whether the mesh is produced by an instruction
Return type:bool

If you get this mesh from knittingpattern.Instruction.InstructionInRow.produced_meshes or knittingpattern.Row.Row.produced_meshes, this should be True.

Warning

Before you use any methods on how the mesh is produced, you should check with mesh.is_produced().

producing_instruction

Instruction which produces this mesh.

Returns:the instruction that produces this mesh
Return type:knittingpattern.Instruction.InstructionInRow

Warning

Check with is_produced() before!

producing_row

Row which produces this mesh.

Returns:the row of the instruction that produces this mesh
Return type:knittingpattern.Row.Row

Warning

Check with is_produced() before!

class knittingpattern.Mesh.ProducedMesh(producing_instruction, index_in_producing_instruction)[source]

Bases: knittingpattern.Mesh.Mesh

A Mesh that has a producing instruction

__init__(producing_instruction, index_in_producing_instruction)[source]
Parameters:
  • producing_instruction – the instruction that produces the mesh
  • index_in_producing_instruction (int) – the index of the mesh in the list of meshes that producing_instruction produces

Note

There should be no necessity to create instances of this directly. You should be able to use instruction.produced_meshes or instruction.consumed_meshes to access the meshes.

class knittingpattern.Mesh.ConsumedMesh(consuming_instruction, index_in_consuming_instruction)[source]

Bases: knittingpattern.Mesh.Mesh

A mesh that is only consumed by an instruction

__init__(consuming_instruction, index_in_consuming_instruction)[source]
Parameters:
  • consuming_instruction – the instruction that consumes the mesh
  • index_in_consuming_instruction (int) – the index of the mesh in the list of meshes that consuming_instruction consumes

Note

There should be no necessity to create instances of this directly. You should be able to use instruction.produced_meshes or instruction.consumed_meshes to access the meshes.