zope.tales

raw JSON →
7.0 verified Mon Apr 27 auth: no python

Implementation of the TAL Expression Syntax (TALES) used by Zope Page Templates (ZPT/TAL). Version 7.0 supports Python >=3.9. Released on an as-needed cadence by the Zope Foundation.

pip install zope.tales
error ModuleNotFoundError: No module named 'zope.tales'
cause Package not installed or installed under a different name.
fix
Run: pip install zope.tales
error ImportError: cannot import name 'ExpressionEngine' from 'zope.tales'
cause Incorrect import path: ExpressionEngine is in the engine submodule.
fix
Use: from zope.tales.engine import ExpressionEngine
error zope.tales.expressions.TALESError: ...
cause Invalid expression syntax (e.g., missing closing brace, wrong path separator).
fix
Ensure expressions use correct TALES syntax: use ${...} for variables, / for path segments, and check parentheses.
breaking Python 3.9 minimum in version 7.0; older Python versions are no longer supported.
fix Upgrade to Python 3.9+ or pin zope.tales to version 6.x.
deprecated The 'namespaces' argument in Engine.evaluate() has been deprecated since 6.0 and may be removed.
fix Use the 'context' argument instead.
gotcha TALES uses a custom expression parser; variable names with dots (e.g., 'request.form') require explicit bracket notation like 'request/ form' or using the 'path:' prefix.
fix Use slash (/) for path traversal: 'request/form' instead of 'request.form'.

Basic example: creates a TALES engine, sets a context variable, evaluates a simple expression.

from zope.tales.engine import Engine
e = Engine()
context = {'name': 'World'}
result = e.evaluate('Hello, ${name}!', context)
print(result)  # outputs: Hello, World!