472,958 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

pydoc preference for triple double over triple single quotes -- anyreason?

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". ("Module docs" referring
to the shortcut installed on Windows that launches the pydoc server.)

It turns out that I was using '''triple single quotes''' and pydoc
only pulls a description out from module docstrings that are formatted
in """triple double quotes""". I've poked about with google, and
cannot find any explanation of why pydoc should treat the two cases
differently. Anyone have an idea?

I do see that both <http://www.python.org/peps/pep-0008.html> -- Style
Guide for Python Code and <http://www.python.org/peps/pep-0257.html>
-- Docstring Conventions suggest triple double, so I guess it is my
fault. But still, those PEP's have the tone of suggestions, and since
the two quoting schemes are semantically equivalent . . .

I do prefer the look of triple-single, but oh well. My attempts to
google for an answer didn't come up with anything, so perhaps this
post will help someone else, if nothing else :-)

Best to all,

Brian vdB

Jul 19 '05 #1
7 3905
Brian van den Broek <bv****@po-box.mcgill.ca> writes:
It turns out that I was using '''triple single quotes''' and pydoc
only pulls a description out from module docstrings that are formatted
in """triple double quotes""". I've poked about with google, and
cannot find any explanation of why pydoc should treat the two cases
differently. Anyone have an idea?


Maybe because some editors, e.g. Emacs, do not (cannot) properly
handle triple quotes in syntax analysis and highlighting. Instead,
the quotes are treated as ordinary quotes, which breaks

'''This doesn't work'''

but not

"""This'll work"""

due to the apostrophe. pydoc then probably decided to follow PEP 257
which says

For consistency, always use """triple double quotes""" around
docstrings.
[http://www.python.org/peps/pep-0257.html]

- Thomas

--
If you want to reply by mail, substitute my first and last name for
'foo' and 'bar', respectively, and remove '.invalid'.
Jul 19 '05 #2
Brian van den Broek wrote:
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". ("Module docs" referring to the shortcut
installed on Windows that launches the pydoc server.)


?? It works for me with triple-single quoted strings...from a quick look it appears that pydoc uses
inspect which looks at the __doc__ attribute; do your modules have __doc__ attributes?

Kent
Jul 19 '05 #3
Kent Johnson said unto the world upon 2005-04-16 16:41:
Brian van den Broek wrote:
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". ("Module docs" referring
to the shortcut installed on Windows that launches the pydoc server.)

?? It works for me with triple-single quoted strings...from a quick look
it appears that pydoc uses inspect which looks at the __doc__ attribute;
do your modules have __doc__ attributes?

Kent

Thanks for the reply, Kent. (Also to Thomas in another reply addressed
below.)

Kent, that's odd. My module does have a valid docstring and hence a
__doc__ attribute (I did explicitly check). help(my_module) works fine
at the prompt. It is just the results list in the TKinter interface to
the pydoc server application that doesn't seem to pick up my module's
description (in the first line of its docstring) when the docstring is
triple-single quoted.

Either way, it's no big deal; my post was at least as much to have a
googleable record of the situation as to figure out why. That said, it
still does puzzle me that the pydoc server treats the two styles of
triple quoted docstrings differently on my system (Python 2.4.1,
Windows Me).

Thomas suggested the preference might be related to Emacs
behaviour--that is something I know little about :-)

He also suggested that it could be that pydoc is following the PEP 257
<http://www.python.org/peps/pep-0257.html> recommendation to use
triple-double quoting. That might be, but if that's the explanation,
it just pushes the puzzle up a level for me :-)

Anyway, thanks again to both,

Brian vdB

Jul 19 '05 #4
Brian van den Broek wrote:
Kent Johnson said unto the world upon 2005-04-16 16:41:
Brian van den Broek wrote:
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". ("Module docs"
referring to the shortcut installed on Windows that launches the
pydoc server.)


?? It works for me with triple-single quoted strings...from a quick
look it appears that pydoc uses inspect which looks at the __doc__
attribute; do your modules have __doc__ attributes?

Kent, that's odd. My module does have a valid docstring and hence a
__doc__ attribute (I did explicitly check). help(my_module) works fine
at the prompt. It is just the results list in the TKinter interface to
the pydoc server application that doesn't seem to pick up my module's
description (in the first line of its docstring) when the docstring is
triple-single quoted.


I'm not sure what you mean by "the results list in the TKinter interface to the pydoc server". I ran
the server, clicked "open browser" and browsed to a module in site-packages; that worked fine for me
under Win2K and Python 2.4.1.

Kent
Jul 19 '05 #5
Kent Johnson said unto the world upon 2005-04-17 16:17:
Brian van den Broek wrote:
Kent Johnson said unto the world upon 2005-04-16 16:41:
Brian van den Broek wrote:

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". ("Module docs"
referring to the shortcut installed on Windows that launches the
pydoc server.)
?? It works for me with triple-single quoted strings...from a quick
look it appears that pydoc uses inspect which looks at the __doc__
attribute; do your modules have __doc__ attributes?

Kent, that's odd. My module does have a valid docstring and hence a
__doc__ attribute (I did explicitly check). help(my_module) works fine
at the prompt. It is just the results list in the TKinter interface to
the pydoc server application that doesn't seem to pick up my module's
description (in the first line of its docstring) when the docstring is
triple-single quoted.

I'm not sure what you mean by "the results list in the TKinter interface
to the pydoc server". I ran the server, clicked "open browser" and
browsed to a module in site-packages; that worked fine for me under
Win2K and Python 2.4.1.

Kent


By "the TKinter interface to the pydoc server" I mean the window that
pops up when you select the Module Docs shortcut. It is pictured here
<http://www.onlamp.com/python/2001/04/18/graphics/pydoc1.gif>, which
is Fig.1 in an article on pydoc by Cameron Laird
<http://www.onlamp.com/pub/a/python/2001/04/18/pydoc.html>. By
"results list" I mean the gray-backround'ed box immediately below the
"Search for" input box in the illustration.

The puzzle for me was that if I enter my module name in the "Search
for" box, it shows up in the list of results, as expected. But whether
the results list entry for my module incorporates the description form
my module's docstring or instead shows my module as having "(no
description)" is a function of which style of triple quotes I used.
(If my module docstring is enclosed by triple double quotes, the
description is extracted from my module's docstring. If it uses triple
single quotes instead, for purposes of the results list my module's
docstring is ignored, and the module is listed as having "(no
description)".)

At any rate, such was the (minor) irritation which caused me to launch
the thread. It took me a bit to work out that the quote-style was what
made the difference, and a preliminary google didn't cast light.
2/3rd's the point of the post was to make the problem resolvable by
google.

Thanks for your continued efforts to understand what I'm on about. :-)

Best to all,

Brian vdB
Jul 19 '05 #6
Brian van den Broek wrote:
Kent Johnson said unto the world upon 2005-04-17 16:17:
Brian van den Broek wrote:
Kent Johnson said unto the world upon 2005-04-16 16:41:

Brian van den Broek wrote:

> 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". ("Module docs"
> referring to the shortcut installed on Windows that launches the
> pydoc server.)
I'm not sure what you mean by "the results list in the TKinter
interface to the pydoc server". I ran the server, clicked "open
browser" and browsed to a module in site-packages; that worked fine
for me under Win2K and Python 2.4.1.


By "the TKinter interface to the pydoc server" I mean the window that
pops up when you select the Module Docs shortcut. It is pictured here
<http://www.onlamp.com/python/2001/04/18/graphics/pydoc1.gif>, which is
Fig.1 in an article on pydoc by Cameron Laird
<http://www.onlamp.com/pub/a/python/2001/04/18/pydoc.html>. By "results
list" I mean the gray-backround'ed box immediately below the "Search
for" input box in the illustration.

The puzzle for me was that if I enter my module name in the "Search for"
box, it shows up in the list of results, as expected. But whether the
results list entry for my module incorporates the description form my
module's docstring or instead shows my module as having "(no
description)" is a function of which style of triple quotes I used. (If
my module docstring is enclosed by triple double quotes, the description
is extracted from my module's docstring. If it uses triple single quotes
instead, for purposes of the results list my module's docstring is
ignored, and the module is listed as having "(no description)".)


OK, now I get it. I don't use pydoc much and I missed that display.

This is indeed a bug in pydoc. If you look at lines 194, 195 and 201 in pydoc.py (Python 2.4.1
version) you can see that it is parsing out the module docstring itself and it only looks for """
strings.

Here is a patch that accepts ''' strings as well. Though a better patch would allow any kind of
string. I filed a bug report at
http://sourceforge.net/tracker/index...70&atid=105470

Kent

194,195c194,195
< if line[:4] == 'r"""': line = line[1:]
< if line[:3] == '"""':
--- if line[:4] == 'r"""' or line[:4] == "r'''": line = line[1:]
if line[:3] == '"""' or line[:3] == "'''": 201c201
< result = strip(split(line, '"""')[0])
--- result = strip(re.split('\'\'\'|"""', line)[0])

Jul 19 '05 #7
Kent Johnson said unto the world upon 2005-04-18 08:20:

<SNIP several iterations clarifying the problem>
The puzzle for me was that if I enter my module name in the "Search
for" box, it shows up in the list of results, as expected. But whether
the results list entry for my module incorporates the description form
my module's docstring or instead shows my module as having "(no
description)" is a function of which style of triple quotes I used.
(If my module docstring is enclosed by triple double quotes, the
description is extracted from my module's docstring. If it uses triple
single quotes instead, for purposes of the results list my module's
docstring is ignored, and the module is listed as having "(no
description)".)

OK, now I get it. I don't use pydoc much and I missed that display.

This is indeed a bug in pydoc. If you look at lines 194, 195 and 201 in
pydoc.py (Python 2.4.1 version) you can see that it is parsing out the
module docstring itself and it only looks for """ strings.

Here is a patch that accepts ''' strings as well. Though a better patch
would allow any kind of string. I filed a bug report at
http://sourceforge.net/tracker/index...70&atid=105470
Kent


<SNIP patch>

Thanks for sticking with this, Kent.

Also, thanks for the patch and for filing the bug. (I had thought of
doing so before posting, but don't yet feel quite confident enough in
my judgement that I'd be putting signal rather than noise into the
bug-tracker.)

Best,

Brian vdB

Jul 19 '05 #8

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

Similar topics

5
by: sinister | last post by:
The examples in the online manual all seem to use double quotes, e.g. at http://us3.php.net/preg_replace Why? (The behavior is different with single quotes, and presumably simpler to...
11
by: Jakanapes | last post by:
Hi all, I'm looking for a way to scan a block of text and replace all the double quotes (") with single quotes ('). I'm using PHP to pull text out of a mySQL table and then feed the text into...
3
by: Anthony Roberts | last post by:
property = re.compile("""(?P<name>+)="(?P<value>.*?)""""re.I) This doesn't work because the closing quote in my regex forms the first quote of a triple quote to end the string... property =...
8
by: Christoph Zwerschke | last post by:
I sometimes use triple quotes in order to produce snippets of multiline code, like that: if output == html: snip = '''<html> <head><title>Hello, World</title></head> <body...
5
by: Joel | last post by:
Hi, I incorporated a function in my code that whenever I use a string variable in an sql statement if the string contains a single quote it will encase it in double quotes else single quotes. ...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
4
by: (PeteCresswell) | last post by:
Is his just a flat-out "No-No" or is there some workaround when it comes time for SQL searches and DAO.FindFirsts against fields containing same? I can see maybe wrapping the value searched for...
7
by: gar | last post by:
Hi, I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code text= Replace(text, """", "'" This works fine (for normal double quotes).The problem...
4
by: Justin Fancy | last post by:
Hi everyone, I need to replace all instances of a double quote(") with two single quotes('') in a text file. I already have some replacements of strings going on, but I tried this one, but the...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.