Variable
Class for handling Variable substitutions.
Variable
Bases: Substitution
Environment Variable class capable of substituting itself into strings.
Derived from the Substitution EnvObject class which requires that a substitution be able to inject itself into data.
Source code in maestrowf/datastructures/environment/variable.py
__init__(name, value, token='$')
Initialize the Variable class.
The Variable represents substrings that can be present within String
data that are meant to be replaced. The general format that such items
take is generally expressed as '
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
String name that refers to a Variable instance. |
required | |
value |
The value to substitute for the Variable instance. |
required | |
token |
String of expected character(s) that appear at the beginning of a substring representing the variable. |
'$'
|
Source code in maestrowf/datastructures/environment/variable.py
__str__()
Generate the string representation of the objects.
Returns:
Type | Description |
---|---|
A string with the token form of the variable. |
get_var()
Get the variable representation of the variable's name.
Returns:
Type | Description |
---|---|
String of the Variable's name in token form. |
substitute(data)
Substitute the variable's value for its notation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
String to substitute variable into. |
required |
Returns:
Type | Description |
---|---|
String with the variable's name replaced with its value. |