InstructionLibrary Module

Instructions have many attributes that do not need to be specified in each knitting pattern set.

This module provides the functionality to load default values for instructions from various locations.

class knittingpattern.InstructionLibrary.InstructionLibrary[source]

Bases: object

This library can be used to look up default specification of instructions.

The specification is searched for by the type of the instruction.

__getitem__(instruction_type)[source]
Returns:the specification for instruction_type

See also

as_instruction()

__init__()[source]

Create a new InstructionLibrary without arguments.

Use load to load specifications.

__weakref__

list of weak references to the object (if defined)

add_instruction(specification)[source]

Add an instruction specification

Parameters:specification – a specification with a key knittingpattern.Instruction.TYPE

See also

as_instruction()

as_instruction(specification)[source]

Convert the specification into an instruction

Parameters:specification – a specification with a key knittingpattern.Instruction.TYPE

The instruction is not added.

load
Returns:a loader that can be used to load specifications
Return type:knittingpattern.Loader.JSONLoader

A file to load is a list of instructions in JSON format.

[
    {
        "type" : "knit",
        "another" : "attribute"
    },
    {
        "type" : "purl"
    }
]
loaded_types

The types loaded in this library.

Returns:a list of types, preferably as string
Return type:list
class knittingpattern.InstructionLibrary.DefaultInstructions[source]

Bases: knittingpattern.InstructionLibrary.InstructionLibrary

The default specifications for instructions ported with this package

INSTRUCTIONS_FOLDER = 'instructions'

the folder relative to this module where the instructions are located

__init__()[source]

Create the default instruction library without arguments.

The default specifications are loaded automatically form this package.

knittingpattern.InstructionLibrary.default_instructions()[source]
Returns:a default instruction library
Return type:DefaultInstructions

Warning

The return value is mutable and you should not add new instructions to it. If you would like to add instructions to it, create a new DefaultInstructions instance.