473,738 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "descriptio n" 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 3114
gr**@conifold.m ath.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 "descriptio n" 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.pytho n
Jul 18 '05 #2
On Fri, 17 Oct 2003 11:34:05 GMT, Michael Hudson <mw*@python.net > wrote:
gr**@conifold. math.ucdavis.ed u (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 "descriptio n" 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
documentatio n 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
2030
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" However, when I run pydoc from the Windows XP command line, it launches my editor (Codewright) and displays pydoc.py in the editor. I want to be able to use it to display docstrings in my modules, from
7
3982
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 didn't extract a description from my module docstrings. Even though I had a well formed docstring (one line, followed by a blank line, followed by the rest of the docstring), when I ran Module docs, my modules showed up as having "no description"....
9
22658
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 show documentation on something."
1
2190
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 application? I've tried to just bind pydoc.gui() to a menu item, but this just brings up the GUI for pydoc, and the user still needs to search for the module before the browser comes up, and when I quit serving pydoc.gui(), my application dies...
3
7449
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 simply pointing it to the package on the command line... pydoc -w <packagename_without_/> Certainly, the method writedocs() appears to descend into a directory
0
970
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, pythonic way (only in Apache). If my source is containing a tag that use this module, or it's submodule, the pydoc is not working.
5
3701
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 tried: $ easy_install pydoc
4
1464
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.) The original pydoc did this a somewhat round about way, so I would like to find a more direct method if possible. Where dir(obj) is used to get all attributes of a module or class. And
0
1239
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 documented all in English, except if I were 110% sure than nobody else would read my docs, but they are only for in-house use). When I tried to use the pydoc tab that SPE attaches to every source file, I only found a message saying that my...
0
8968
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9473
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
9334
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
9259
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
9208
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
8208
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
6750
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
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.