-
Book Overview & Buying
-
Table Of Contents
Metaprogramming with Python
By :
In this section, we will look at generating code for multiple classes dynamically using the ast module and its unparse method.
Generating the code for more than one class dynamically gives us a direction for implementing code generation for multiple functionalities of an application. The classes need not be for the same functionality and the class code thus generated can later be modified to include additional methods or attributes as required by the application. The skeletal class code will be generated through this example.
To understand this further, we will follow the sequence described in the following flow diagram.
Figure 14.3 – A code generation sequence for multiple classes
Let us now look at how to implement this scenario:
classnames = ["VegCounter", "ElectronicsCounter", "PasadenaBranch...