spyce
         
home     documentation     download     Spyce logo


Documentation - Runtime

Prev: 3.1 - Exceptions Up: 3 - Runtime Next: 3.3 - Dynamic Content

3.2. Code Transformation

While the minutia of the code transformation that produces Python code from the Spyce sources is of no interest to the casual user, it has some slight, but important, ramifications on certain aspects of the Python language semantics when used inside a Spyce file.

The result of the Spyce compilation is some Python code, wherein the majority of the Spyce code actually resides in a single function called spyceProcess. If you are curious to see the result of a Spyce compilation, execute: "spyce -c".

It follows from the compilation transformation that:

  • Any functions defined within the Spyce file are actually nested functions within the spyceProcess function.
  • The use of global variables within Spyce code is not supported, but also not needed. If nested scoping is available (Python versions >2.1) then these variables will simply be available. If not, then you will need to pass variables into functions as default parameters, and will not be able to update them by value (standard Python limitations). It is good practice to store constants and other globals in a single class, or to to place them in a single, included file, or both.
  • The global Spyce namespace is reserved for special variables, such as Spyce and Python modules. While the use of the keyword global is not explicitly checked, it will pollute this space and may result in unexpected behaviour or runtime errors.

  • The lifetime of variables is the duration of a request. Variables with lifetimes longer than a single request can be stored using the pool module.


Prev: 3.1 - Exceptions Up: 3 - Runtime Next: 3.3 - Dynamic Content


Spyce logo
Python Server Pages
version 2.1.3
Spyce Powered SourceForge Logo