473,382 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How does pydoc parse code?

I plan to use pydoc for my Python project. After looking through the
standard documentation, I am not sure how pydoc interprets its input.
In its basic operation it evidently looks at the first string literal in
the module and in each function definition. But there is more to the
story than that, obviously. What other vestigial code does it detect?
Every string literal? Variables of the form __xxx__, I gather? Which of
these variables have a special meaning? How does it divide the initial
string literal into the "name" and "description" sections? What other
directives can I send to pydoc to alter its presentation?

For instance, I might want a revision history for each module listed
before the description. Is there a way to do that? Or I might want
to suppress the __xxx__ variables used by pydoc from the data section.
Is there a way to do that? What *can* I do?

Given that it is a documentation facility, pydoc isn't all that well
documented. :-) At least not at this page:

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

And this is hardly better:

pydoc /usr/lib/python2.2/pydoc.py
--
/\ Greg Kuperberg (UC Davis)
/ \
\ / Visit the Math ArXiv Front at http://front.math.ucdavis.edu/
\/ * All the math that's fit to e-print *
Jul 18 '05 #1
2 3099
gr**@conifold.math.ucdavis.edu (Greg Kuperberg) writes:
I plan to use pydoc for my Python project. After looking through the
standard documentation, I am not sure how pydoc interprets its input.
In its basic operation it evidently looks at the first string literal in
the module and in each function definition. But there is more to the
story than that, obviously. What other vestigial code does it detect?
Every string literal? Variables of the form __xxx__, I gather? Which of
these variables have a special meaning? How does it divide the initial
string literal into the "name" and "description" sections? What other
directives can I send to pydoc to alter its presentation?
It would be nice if there was a concise, simple place in the
documentation I could point you to to answer that question.

Alas, it does what it does, and that's about all that can be said.

Oh, and it *doesn't* parse the module: it imports and then introspects
it.
For instance, I might want a revision history for each module listed
before the description. Is there a way to do that? Or I might want
to suppress the __xxx__ variables used by pydoc from the data section.
Is there a way to do that? What *can* I do?
Beats me. You might be happier with one of the other documentation
tools like epydoc or happydoc (both at SF) but I know very little
about them...

Cheers,
mwh

-- I'm a little confused.

That's because you're Australian! So all the blood flows to
your head, away from the organ most normal guys think with.
-- Mark Hammond & Tim Peters, comp.lang.python
Jul 18 '05 #2
On Fri, 17 Oct 2003 11:34:05 GMT, Michael Hudson <mw*@python.net> wrote:
gr**@conifold.math.ucdavis.edu (Greg Kuperberg) writes:
I plan to use pydoc for my Python project. After looking through the
standard documentation, I am not sure how pydoc interprets its input.
In its basic operation it evidently looks at the first string literal in
the module and in each function definition. But there is more to the
story than that, obviously. What other vestigial code does it detect?
Every string literal? Variables of the form __xxx__, I gather? Which of
these variables have a special meaning? How does it divide the initial
string literal into the "name" and "description" sections? What other
directives can I send to pydoc to alter its presentation?


It would be nice if there was a concise, simple place in the
documentation I could point you to to answer that question.

Alas, it does what it does, and that's about all that can be said.

Oh, and it *doesn't* parse the module: it imports and then introspects
it.


I wonder if we shouldn't take that seriously. E.g., check the file's md5
against a set (or dict, so you could ask why if a name change) of known safe
module sources and issue a (untested)

if not raw_input("""
WARNING: Module is not known to system.
There is a SECURITY RISK in proceeding, because pydoc executes the module
by importing it to make the doc info available to it via inspect.

Proceed anyway? (only typing exactly "Yes" w/o quotes will proceed): """
)=='Yes': raise SystemExit, 'Unsafe pydoc inspection abandoned by user.'

if not found. You could also give the user the option to declare a given module
trusted by having the md5 set persist in site info, for convenience.

Regards,
Bengt Richter
Jul 18 '05 #3

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

Similar topics

0
by: Tony C | last post by:
According to the help for pydoc, it can be run as a script, from the command line. "Or, at the shell command line outside of Python: Run "pydoc <name>" to show documentation on something" ...
7
by: Brian van den Broek | last post by:
Hi all, I'm posting partly so my problem and solution might be more easily found by google, and partly out of mere curiosity. I've just spent a frustrating bit of time figuring out why pydoc...
9
by: newsposter | last post by:
>>> import pydoc >>> import sys >>> sys.version '2.4.2 (#67, Sep 28 2005, 12:41:11) ' >>> pydoc sys SyntaxError: invalid syntax >>> The documentation for pydoc says: "Run "pydoc <name>" to...
1
by: timw.google | last post by:
Hi all, I'm discovering pydoc, and it seems to me that this is a great way to have online documentation for my application. Are there any examples of using this in some kind of help menu in an...
3
by: Rob Cowie | last post by:
I have searched this group and the wider net to find an answer to this, but I haven't been successful. Pydoc seems to be capable of writing documentation for all modules within a package by...
0
by: durumdara | last post by:
Hi ! I need to write documentation for my mod_python website, for the base classes, functions, modules. The problem, that mod_python is imported "apache" that not existing in the normal,...
5
by: Wijaya Edward | last post by:
I tried to call pydoc from my Linux box. To my realization that it doesn't contain pydoc. I thought this module should be a default module. Can anybody suggest where can I find the module? I...
4
by: Ron Adam | last post by:
This is for a new version of pydoc if I can get the class attributes sorted out. The module level attributes aren't too difficult to categorize. (I might be just too tired to see the obvious.) ...
0
by: w.m.gardella.sambeth | last post by:
Hello Pythonists: I am using SPE as python IDE on Windows, with Python 2.5.1 installed (official distro). As my mother tongue is Spanish, I had documented some modules in it (I now, I should have...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.