473,748 Members | 11,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python "header" files

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.
Jul 18 '05 #1
7 25581
be*******@aol.c om 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."
Jul 18 '05 #2
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 NotImplementedE rror in each of its functions.

HTH.

Bye.
--
-------------------------------------------------------------------------
Miki Tebeka <mi*********@zo ran.com>
The only difference between children and adults is the price of the toys.

Jul 18 '05 #3
be*******@aol.c om 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>\Too ls\scripts\pydo cgui.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
Jul 18 '05 #4
be*******@aol.c om 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.

Jul 18 '05 #5
be*******@aol.c om 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
Jul 18 '05 #6
Timo Virkkala <a@a.invalid> wrote in message news:<9r******* ********@read3. inet.fi>...
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.
Jul 18 '05 #7
be*******@aol.c om 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
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
11576
by: Chris Markle | last post by:
When JavaScript writes out a dialogue box (like when confirm() is called) the header or title of that dialogue box shows up as "JavaScript Application"... Can this title be changed so that maybe you could stick the name of your application in it?
16
2914
by: a | last post by:
Hi everybody, My config: Win XP (or 2003), Apache 2.0.54, PHP 5.1.2. I have been trying to handle the case of a lenghty opearation on the server while providing the user with feedback and ability to cancel, and nothing seems to work so far. The following code is one attempt to address this, and it is called as result of a POST:
9
6078
by: Richard Lionheart | last post by:
Hi All, I've got Visual Studio .Net installed, but I don't know it very well. So I tried to create a plain old Win32 using the command-line complier. I tried to compile: ************ HelloWorld.cpp ************* #include "stdafx.h" void main()
6
1574
by: dhillarun | last post by:
Hi everybody, I displaying file download window("save-as dialog box") using PHP "header()" function. How to track that user have clicked "save" button or "cancel" button???
25
1914
by: mdh | last post by:
Hi all, Going quite methodically through K& R ( as some of you can attest to!), I have never seen a big diffference in declaring a function within "main" or "ahead" of it. Now, (p119, K&R II), the discussion states that "functions "whatever" " should be declared ahead of main. Is there a good reason for this? thanks.
1
1695
by: kang jia | last post by:
hi i don;t know what is the difference between"Header" and "Meta" data in PHP, as they all can redirect web page. anyone can help me, it is very urgent!! thaks
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.