Element extensions¶
Utilities for element extensions in PrairieLearn.
from prairielearn import ...
clean_identifier_name ¶
Escapes a string so that it becomes a valid Python identifier.
Returns:
Type | Description |
---|---|
str
|
The input as a valid Python identifier |
load_all_extensions ¶
load_all_extensions(data: QuestionData) -> dict[str, Any]
Load all available extensions for a given element.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
An ordered dictionary mapping the extension name to its defined variables and functions |
Raises:
Type | Description |
---|---|
ValueError
|
If the element does not have any extensions defined. |
load_extension ¶
load_extension(
data: QuestionData, extension_name: str
) -> Any
Load a single specific extension by name for an element.
Returns:
Type | Description |
---|---|
Any
|
A dictionary of defined variables and functions. |
Raises:
Type | Description |
---|---|
ValueError
|
If the extension isn't defined in the provided |
load_host_script ¶
load_host_script(script_name: str) -> ModuleType
Small convenience function to load a host element script from an extension.
Returns:
Type | Description |
---|---|
ModuleType
|
The imported module |