Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python "header" files

Reply
Thread Tools

Python "header" files

 
 
beliavsky@aol.com
Guest
Posts: n/a
 
      06-08-2004
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.

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.
 
Reply With Quote
 
 
 
 
Timo Virkkala
Guest
Posts: n/a
 
      06-08-2004
wrote:
> 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.


Probably the most convenient way is to write good docstrings which document
the return values as well, and then generate static documentation from them
with pydoc.

http://www.python.org/doc/current/lib/module-pydoc.html

--
Timo "WT" Virkkala

"In the battle between you and the world, bet on the world."
 
Reply With Quote
 
 
 
 
Nicolas Fleury
Guest
Posts: n/a
 
      06-08-2004
wrote:
> 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?


You don't want to do that. Use pydoc utilities instead. If you use
Windows with ActivePython, look at <PythonDir>\Tools\scripts\pydocgui.pyw.

Headers in C++ are there by obligation, not by choice. Expect that to
disappear the day modules are introduced in C++ (still dreaming).

Regards,
Nicolas
 
Reply With Quote
 
Miki Tebeka
Guest
Posts: n/a
 
      06-08-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 <>
The only difference between children and adults is the price of the toys.

 
Reply With Quote
 
Donald 'Paddy' McCarthy
Guest
Posts: n/a
 
      06-09-2004
wrote:
> 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.
>
> 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.


You could use doctest:
http://www.python.org/doc/current/li...e-doctest.html
- together with meaningful docstring comments and pydoc:
http://www.python.org/doc/current/lib/module-pydoc

You might try help() in the interpreter on a few functions or modules
for inspiration.

Cheers, Pad.

 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      06-09-2004
wrote:
> 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.


We had over a dozen Python programmers working on the same
project and didn't find it particularly a problem that the
full source code was available to them. In fact, given that
it was an XP environment (Extreme Programming, that is, though
it was also a partly WinXP environment) it was a huge
advantage over situations where only sketchy and inaccurate
documentation was available.

In the past, any time I've been limited to header files and
the docs I've encountered serious troubles. The header
files are often a mess, because of the inherent duplication,
inline code makes them even less readable, and the
documentation is _never_ maintained properly.

-Peter
 
Reply With Quote
 
beliavsky@aol.com
Guest
Posts: n/a
 
      06-09-2004
Timo Virkkala <> wrote in message news:<9rqxc.493$>...

> Probably the most convenient way is to write good docstrings which document
> the return values as well, and then generate static documentation from them
> with pydoc.
>
> http://www.python.org/doc/current/lib/module-pydoc.html


Thanks to you and others for suggesting pydoc. It easily generates
nice HTML. I like the results for my modules that just define
functions and classes.

For the main programs it actually runs the Python code and does
calculations before producing HTML. (Pychecker seems to work the same
way). The "DATA" section contains not only the parameters I set but
the computed results, which can change every time the program is run,
especially for simulations. PyDoc does not seem too helpful to me for
documenting the main program.

I think the HTML documentation for a main program should have (in
addition to the docstrings) the list of modules imported with links to
specific functions and variables imported.
 
Reply With Quote
 
David Bolen
Guest
Posts: n/a
 
      06-09-2004
writes:

> For the main programs it actually runs the Python code and does
> calculations before producing HTML. (Pychecker seems to work the same
> way). The "DATA" section contains not only the parameters I set but
> the computed results, which can change every time the program is run,
> especially for simulations. PyDoc does not seem too helpful to me for
> documenting the main program.


It sounds like you haven't protected your main script against being
imported as a module. It's not so much that pydoc/Pychecker are
"running" your Python code, but that they are importing the modules to
get at the information. While it's possible to write such a tool that
would instead compile the module and then analyse the resultant
compiled form, it's much easier to just introspect the normal Python
objects as a result of an import, so you'll find that most
introspection tools use the import-and-process approach. It does have
the side-effect of performing the import (so if modules do
calculations or operations when imported, that get's triggered).

If you haven't already, protect any top-level code in your main
modules inside an:

if __name__ == "__main__":

block, and you won't find your code running when the module is
processed by tools such as these.

-- David
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check what symbols are defined in a .o files? .a files? and.so files in linux? yinglcs@gmail.com C++ 3 01-18-2009 05:23 PM
using python with tar files and compressed files John Salerno Python 3 08-10-2006 02:17 PM
how i can extract text from the PDF files,power point files,Ms word files? crazyprakash Java 4 10-30-2005 10:17 AM
Text files read multiple files into single file, and then recreate the multiple files googlinggoogler@hotmail.com Python 4 02-13-2005 05:44 PM
Help! Files, Files, and more Files ... Everywhere JeffS Digital Photography 22 09-19-2004 01:47 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57