Methods

The Ringing Class Library provides many useful functions for dealing with methods, finding information about them and classifying them.

A method consists of one block of changes which is repeated over and over again; this is called a lead. If, at the end of one lead, every bell is in a different position, then the method is called a principle and the leads are called divisions. Any bells in a method which end up in the same place at the end of a lead are called hunt bells.

The Ringing Class Library defines a Method object which is simply a block of changes and which provides a large range of member functions. Many of these are used for finding out things about the method, such as the number of leads in the plain course, the type of method, the full name and so on.

The Method Class

The Method class represents a method by storing the changes which make up one lead of the method.

A method may have a name, which is a string variable. This name is the base name of the method, that is, it is the name without any extra bits such as “Surprise” or “Triples”. For example, the base name of Plain Bob Major is simply “Plain”. The parts of the name other than the base can be worked out by the Ringing Class Library.

class ringing.Method([spec=None][, bells=0][, name='Untitled'])

Constructs a Method.

Methods may be constructed in a variety of ways:

>>> from ringing import Method
>>> Method(2, 4)  # from an integer length
Method('1234.1234', 4, 'Untitled')
>>> Method('&-1-1,2', 4)  # from a place notation
Method('&-14-14,12', 4, 'Untitled')
>>> Method(Method())  # from another method
Method('', 0, 'Untitled')

Note

The number of bells defaults to zero. If unspecified, any string of place notation will be decomposed into zero-bell changes, with ValueError exceptions raised for any out-of-range notations. Always specify the number of bells!

A method behaves much like a list of Change objects, and supports the following sequence operations:

Operation

Result

c in m

True if an item of m is equal to c, else False

c not in m

False if an item of m is equal to c, else True

m[i]

ith change of m, origin 0

m[i] = c

sets ith change of m

len(m)

length (size) of m

list(m)

list of changes in m

m.append(c)

appends c to the end of the method

The syntax of the place notation is as follows: place notation consists of a sequence of blocks, which are delimited by commas. Each block is a sequence of changes, with X or - meaning a cross change. Changes other than cross changes are separated by full stops. A block may optionally be preceded by an ampersand &, which means that the entire block, except the last change, is repeated backwards. All other characters are ignored.

Parameters:
  • spec (Method or int or string) –

    Specification for constructing the method. This might be:

    • Nothing. Constructs a zero-length method.

    • Another method. Constructs a copy.

    • An integer length. Constructs a method of the specified length.

    • A string (unicode or bytes) place notation.

  • bells (int) – number of bells

  • name (string) – base name of the method

__lt__(method)
__le__(method)
__eq__(method)
__ne__(method)
__gt__(method)
__ge__(method)

Compares a method to another.

Parameters:

method (Method) – value to compare

Returns:

result

Return type:

boolean

size

Number of changes in a lead of the method:

>>> from ringing import Method
>>> Method('&-1-1-1,2', 6).size
12
length

Synonym for size.

bells

Number of bells on which the method is defined:

>>> from ringing import Method
>>> Method('&-1-1-1,2', 6).bells
6
name

Base name of the method. Note that this may be an empty string, for example in Little Bob. Unlike many attributes in this library, a new value may be assigned to this attribute:

>>> from ringing import Method
>>> m = Method('&-1-1-1,2', 6)
>>> m.name
'Untitled'
>>> m.name = 'Plain'
>>> m
Method('&-16-16-16,12', 6, 'Plain')
append(change)

Adds a change to the end of the method. The change may be provided as a Change object or a string containing the place notation to be added.

Parameters:

change (Change or string) – change to be added

lead_head()

Returns the first lead head of the method:

>>> from ringing import Method
>>> Method('&-1-1-1,2', 6).lead_head()
Row('135264')
Returns:

first lead head

Return type:

Row

leads()

Returns the number of leads in the plain course of the method. This is equivalent to the order of the lead-head row:

>>> from ringing import Method
>>> Method('&-1-1-1,2', 6).leads()
5
>>> Method('&-1-1-1,2', 6).lead_head().order()
5
Returns:

number of leads

Return type:

int

is_regular()

Returns True if the method is regular (that is, it has Plain Bob lead heads), or False otherwise.

Returns:

whether the method is regular

Return type:

boolean

lh_code()

Returns the standard code for the lead end and lead head of the method:

>>> from ringing import Method
>>> Method('&-1-1-1,2', 6).lh_code()
'a'
Returns:

lead head code

Return type:

string

hunt_bells()

Returns the number of hunt bells in the method:

>>> from ringing import Method
>>> Method('&-1-1-1,2', 6).hunt_bells()
1
Returns:

number of hunt bells

Return type:

int

is_symmetric([bell])

Returns True if the method is symmetrical about the half lead (and has an even number of changes in the lead), or False otherwise. If a bell number is specified, returns True if the path of that bell in a lead of the method is symmetrical about the half lead, or False otherwise.

Parameters:

bell (Bell or string or int) – bell to check

Returns:

whether the method is symmetric

Return type:

boolean

is_palindromic([bell])

Returns True if the method is symmetrical about any point (and has an even number of changes in the lead), or False otherwise. If a bell number is specified, returns True if the path of that bell in a lead of the method is symmetrical about any point, or False otherwise.

Parameters:

bell (Bell or string or int) – bell to check

Returns:

whether the method is symmetric

Return type:

boolean

is_double()

Returns True if the method is double, or False otherwise. Note that double does not imply symmetrical.

Returns:

whether the method is double

Return type:

boolean

max_blows()

Returns the maximum consecutive blows made in any place in this method. (If the method has one bell fixed throughout, the lead length is returned.):

>>> from ringing import Method
>>> Method('&-1-1-1,2', 6).max_blows()
2
Returns:

maximum consecutive blows

Return type:

int

is_plain([bell])

Returns True if bell plain hunts for the whole lead of the method, or False otherwise.

If bell is not provided then the treble path is checked.

Parameters:

bell (Bell or string or int) – bell to check

Returns:

whether the bell plain hunts

Return type:

boolean

has_dodges(bell)

Returns True if bell dodges during the lead, or False otherwise.

Parameters:

bell (Bell or string or int) – bell to check

Returns:

whether the bell dodges

Return type:

boolean

has_places(bell)

Returns True if bell makes any internal places during the lead, or False otherwise.

Parameters:

bell (Bell or string or int) – bell to check

Returns:

whether the bell makes internal places

Return type:

boolean

full_name()

Assembles the full name of the method:

>>> from ringing import Method
>>> Method('&-1-1-1,2', 6, 'Plain').full_name()
'Plain Bob Minor'

The full name consists of: * the base name of the method; * the word “Little”, if appropriate; * the class of the method, or none if it is a principle; * the stage (number of bells) of the method

Note that Grandsire, Union and their related methods are treated specially: the full name of these methods does not include their class, nor in the case of Little Grandsire does it contain “Little”.

Returns:

full name

Return type:

string

static stage_name(bells)

Returns a string describing the stage of bells bells: thus “Minimus”, “Doubles”, and so on:

>>> from ringing import Method
>>> Method.stage_name(8)
'Major'

For stages above Sixteen, the number is given in digits.

Parameters:

bells (int) – number of bells

Returns:

stage name

Return type:

string

format(**kwargs)

Formats the method’s place notation into a string:

>>> from ringing import Method
>>> Method('&-1-1-1,2', 6).format(
...     all_dots=True,
...     external_places=True,
...     cross_lower_x=True,
... )
'x.16.x.16.x.16.x.16.x.16.x.12'

Set keyword arguments listed below to True to control the format.

Warning

Some arguments conflict with each other (e.g. cross_upper_x and cross_lower_x); if used together then the result is undefined.

Warning

The symmetry and full_symmetry options may not be used for methods that have an odd number of changes. This is a constraint of the underlying library.

Parameters:
  • all_dots (boolean) – include all dots

  • external_places (boolean) – include all external places

  • cross_upper_x (boolean) – use an ‘X’ for the cross change

  • cross_lower_x (boolean) – use an ‘x’ for the cross change

  • cross_dash (boolean) – use a ‘-’ for the cross change

  • symmetry (boolean) – split palindromic methods into two components

  • full_symmetry (boolean) – as above but with other symmetry points

  • omit_lh (boolean) – omit the lead head change

  • asymmetric_plus (boolean) – prefix asymmetric sections with ‘+

Returns:

formatted place notation

Return type:

string

Raises:

ValueError for symmetry flags with an odd-length method