Python "header" files

Miki Tebeka miki.tebeka at zoran.com
Tue Jun 8 18:57:15 EDT 2004


Hello,

> Ideally, one can use someone's C++ code by just looking at the header
> files
> (which should contain comments describing the functions in addition to
> function definitions), without access to the full source code. Can
> analogs of C++ header files be created for Python code?
> Python "header" files could list only the 'def' statements and
> docstrings of Python functions and classes, but that does not tell you
> what the functions return. One could list the return statements as
> well, but there can be several of them in a function, and they often
> show HOW something is calculated, which is "too much information" for
> a header file.
Why. The header files are source to a lot of mistakes:
1. Using wrong header files
2. Reading header file twice
3. ...
All of it stems from the fact that there are *two* places where you
define the code.
I agree that you should document the code well. If you like something
like header files use pydoc (or teud or whatever) to generate the
documentation from the code.

> I wonder how Python projects with multiple programmers can be
> coordinated without giving all programmers access to all of the source
> code. I am currently working on one-man projects, but I am still
> interested in ways of separating interface from implementation.
This is another subject. There are several ways to create interfaces in
Python (search the cookbook). The most trivial one is to create a base
class the raises NotImplementedError in each of its functions.

HTH.

Bye.
--
-------------------------------------------------------------------------
Miki Tebeka <miki.tebeka at zoran.com>
The only difference between children and adults is the price of the toys.




More information about the Python-list mailing list