Chapter 10. User Modules

Table of Contents
The make_eiffel_module Python script
The script
User modules at work: the re_test example
Extending the "user-defined class" concept to entire Python modules

The ability to shadow an entire Python class with an equivalent Eiffel construct is significant, but does have its limits. Since Python is a procedural language with some object-oriented features, it also relies heavily on modules--collections of classes and functions which do not necessarily fit the strict object-oriented module. By creating a USER_MODULE class an another Python script, we can "export" entire Python modules at once into Eiffel-compatible versions.


Our previous example showed how to take the Python smtplib.SMTP class, shadow it into an equivalent Eiffel class, and use it from within an Eiffel program with relatively little effort. This is fairly significant, and would probably cover many cases of Eiffel-Python interactivity in a very satisfying manner.

Unfortunately, it does not cover everything--not even close. The problem is that, while Eiffel is a pure object-oriented language, Python is really very procedural, with the object-orientation an optional facet of the language. While the finest (and only) granularity of Eiffel is the class, Python allows nesting of classes, functions, and other objects into modules--and we have not discussed how to use modules from within Eiffel yet.

Such a capability is badly needed. Many modules, such as the extremely powerful re (for regular expression searches a la Perl), are only really usable in module format--the developer must have access to both functions and classes in order to use the Python library with any degree of expressive power.