.. automodule:: ZConfig.substitution
This module provides a basic substitution facility similar to that
found in the Bourne shell (sh
on most UNIX platforms).
The replacements supported by this module include:
Source | Replacement | Notes |
---|---|---|
$$ |
$ |
|
$name |
The result of looking up name | |
${name} |
The result of looking up name | |
$(name) |
The result of looking up name in the environment |
Notes:
- This is different from the Bourne shell, which uses
\$
to generate a$
in the result text. This difference avoids having as many special characters in the syntax. - Any character which immediately follows name may not be a valid character in a name.
In each case, name is a non-empty sequence of alphanumeric and underscore characters not starting with a digit. If there is not a replacement for name, the exception :exc:`~.SubstitutionReplacementError` is raised. Note that the lookup is expected to be case-insensitive; this module will always use a lower-case version of the name to perform the query.
This module provides these functions:
.. autofunction:: substitute
.. autofunction:: isname
>>> from ZConfig.substitution import substitute
>>> d = {'name': 'value',
... 'top': '$middle',
... 'middle' : 'bottom'}
>>>
>>> substitute('$name', d)
'value'
>>> substitute('$top', d)
'$middle'