metawards.Interpret

class metawards.Interpret[source]

This is a static class that provides some routines for interpreting values from inputs (normally strings). This is used heavily by code that reads values from the user or from files

__init__()

Initialize self. See help(type(self)) for accurate signature.

Methods

__delattr__(name, /)

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__(value, /)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__gt__(value, /)

Return self>value.

__hash__()

Return hash(self).

__init__()

Initialize self.

__init_subclass__

This method is called when a class is subclassed.

__le__(value, /)

Return self<=value.

__lt__(value, /)

Return self<value.

__ne__(value, /)

Return self!=value.

__new__(**kwargs)

Create and return a new object.

__reduce__()

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__()

Return repr(self).

__setattr__(name, value, /)

Implement setattr(self, name, value).

__sizeof__()

Size of object in memory, in bytes.

__str__()

Return str(self).

__subclasshook__

Abstract classes can override this to customize issubclass().

boolean(s[, rng])

Interpret and return a boolean (True or False) using the passed random number generator if this is a request for a random boolean

date(s[, allow_fuzzy])

Return a Python datetime.date object from the passed ‘s’, allowing fuzzy dates if ‘allow_fuzzy’ is true

day(s[, rng, minval, maxval])

Return a day number (integer) from the passed ‘s’.

day_or_date(s[, rng, minval, maxval, …])

Convenience function that matches a day or a date from the passed ‘s’

integer(s[, rng, minval, maxval])

Interpret and return an integer from ‘s’, using the passed random number generator if this is a request for a random integer, and within the specified bounds of ‘minval’ and ‘maxval’ if needed.

number(s[, rng, minval, maxval])

Interpret and return a number (integer or float) using the passed random number generator if this is a request for a random number, and within the specified bound of ‘minval’ and ‘maxval’ is needed

random_integer([s, rng, minval, maxval])

Interpret a random integer from the passed string, specifying the random number generator to use, and optionally adding additional constraints on the minimum and maximum values

random_number([s, rng, minval, maxval])

Interpret a random number (float) from the passed string, specifying the random number generator to use, and optionally adding additional constraints on the minimum and maximum values

string(s)

Interpret and return a string from ‘s’

Attributes

__dict__

__doc__

__module__

__weakref__

list of weak references to the object (if defined)

static boolean(s: any, rng=None) → bool[source]

Interpret and return a boolean (True or False) using the passed random number generator if this is a request for a random boolean

static date(s: any, allow_fuzzy: bool = True)[source]

Return a Python datetime.date object from the passed ‘s’, allowing fuzzy dates if ‘allow_fuzzy’ is true

static day(s: any, rng=None, minval: int = None, maxval: int = None) → int[source]

Return a day number (integer) from the passed ‘s’. This is a shorthand for ‘integer’, but may take on more meaning if the day needs to be more specialised

static day_or_date(s: any, rng=None, minval: int = None, maxval: int = None, allow_fuzzy: bool = True)[source]

Convenience function that matches a day or a date from the passed ‘s’

static integer(s: any, rng=None, minval: int = None, maxval: int = None) → int[source]

Interpret and return an integer from ‘s’, using the passed random number generator if this is a request for a random integer, and within the specified bounds of ‘minval’ and ‘maxval’ if needed.

This can interpret ‘s’ as an expression, e.g. “6 / 3” etc.

static number(s: any, rng=None, minval: Union[int, float] = None, maxval: Union[int, float] = None) → Union[int, float][source]

Interpret and return a number (integer or float) using the passed random number generator if this is a request for a random number, and within the specified bound of ‘minval’ and ‘maxval’ is needed

This can interpret ‘s’ as an expression, e.g. “2.4 * 3.6” etc.

static random_integer(s: str = None, rng=None, minval: int = None, maxval: int = None) → int[source]

Interpret a random integer from the passed string, specifying the random number generator to use, and optionally adding additional constraints on the minimum and maximum values

static random_number(s: str = None, rng=None, minval: float = None, maxval: float = None) → float[source]

Interpret a random number (float) from the passed string, specifying the random number generator to use, and optionally adding additional constraints on the minimum and maximum values

static string(s: any) → str[source]

Interpret and return a string from ‘s’