ANN: Python Language Reference

S

Stephen Ferg

An attempt to produce a complete, alphabetized reference of all of
Python's language features. The purpose is support developers, who
need a quick way to look up information about a language feature.

The table of contents was extracted from:
* the index of the language reference
* the index of the library reference
* the global module index

http://www.ferg.org/pyref/index.html
 
A

Aahz

An attempt to produce a complete, alphabetized reference of all of
Python's language features. The purpose is support developers, who
need a quick way to look up information about a language feature.

The table of contents was extracted from:
* the index of the language reference
* the index of the library reference
* the global module index

http://www.ferg.org/pyref/index.html

Looks good! I've added it to my bookmark list. Note that there's at
least some missing stuff: __new__() isn't there. You might want to add
descrintro to your set of resources.
 
E

Erik Max Francis

Stephen said:
An attempt to produce a complete, alphabetized reference of all of
Python's language features. The purpose is support developers, who
need a quick way to look up information about a language feature.

The table of contents was extracted from:
* the index of the language reference
* the index of the library reference
* the global module index

http://www.ferg.org/pyref/index.html

It looks like a great reference. The only suggestion I would make is to
chop up the table of contents into smaller pieces since it's so large.
It's not so verbose that there shouldn't _also_ be an option contain
everything, but I think for casual browsing it'd be better to have
separate contents pages for, say, each letter.
 
E

Edward C. Jones

Stephen said:
An attempt to produce a complete, alphabetized reference of all of
Python's language features. The purpose is support developers, who
need a quick way to look up information about a language feature.

The table of contents was extracted from:
* the index of the language reference
* the index of the library reference
* the global module index

http://www.ferg.org/pyref/index.html

Neat.

I have some code I find to be very useful. It searches all the Python
documentation trying to match a regular expression. HTML in the docs is
ignored. The result is formatted in HTML and put where my browser can
find it.

==============================================================
docsdata.py:

#! /usr/bin/env python
from __future__ import generators

import os, sys, time, re, htmllib, formatter, cStringIO, string, cPickle

""" Strips html from Python docs.

./docsdata.py <dir> <datafile>
"""

# Look at the source code for htmllib.
class Parser(htmllib.HTMLParser):
def __init__(self, formatter, verbose=0):
htmllib.HTMLParser.__init__(self, formatter, verbose)

# Print nothing for </a>.
def anchor_end(self):
if self.anchor:
self.anchor = None

# Look at the source code for formatter.
class StripWriter(formatter.DumbWriter):
def __init__(self, f=None, maxcol=72):
formatter.DumbWriter.__init__(self, f, maxcol)

# Ignore horizontal rules.
def send_hor_rule(self, *args, **kw):
self.file.write('\n\n')
self.col = 0
self.atbreak = 0

# Don't cut long lines into pieces.
def send_flowing_data(self, data):
formatter.DumbWriter.send_literal_data(self, data)

# Strip all the html from a piece of text.
def strip_file(textin):
memfile = cStringIO.StringIO()
form = formatter.AbstractFormatter(StripWriter(memfile))
parser = Parser(form)
parser.feed(textin)
title = parser.title
parser.close()
text = memfile.getvalue()
memfile.close()
return title, text

def process_files(topdir, exts):
count = 0
bigdict = {}
bigdict[None] = topdir
count = 0
for dirpath, dirnames, filenames in os.walk(topdir):
for name in filenames:
fullname = os.path.join(dirpath, name)
if not os.path.isfile(fullname):
continue
root, ext = os.path.splitext(fullname)
if ext.lower() not in exts:
continue
text = open(fullname, 'r').read()
title, text = strip_file(text)
size = len(text)
oldsize = 0
while size != oldsize:
text = text.replace('\n\n', '\n')
oldsize = size
size = len(text)
if title is None or title.strip() == '':
title = fullname
bigdict[fullname] = [title, text]
count += 1
if count % 50 == 0:
print 'file count', count
print 'final count', count
return bigdict

if len(sys.argv) != 3:
raise Exception, 'program must have exactly two arguments.'
topdir = sys.argv[1]
datafile = sys.argv[2]

bigdict = process_files(topdir, ['.html', '.htm'])
cPickle.dump(bigdict, file(datafile, 'w'), 1)

===================================================================
doc_search.py:

#! /usr/bin/env python
from __future__ import generators

import os, sys, time, re, htmllib, formatter, cStringIO, string, cPickle

""" Searches for text from Python documentation that matches a regex
pattern.

./doc_search.py <datafile> <pattern>
where <datafile> has been output by "docsdata.py" and <pattern> is a
regex pattern as defined in module "re". The output is a page of html
which is put in NONCE_DIR. A link to the output is added to NONCE_FILE.
"""
NONCE_DIR = '/home/edcjones/nonce_files'
NONCE_FILE = '/home/edcjones/bookmarks/nonce.html'
BEFORE = 50
AFTER = 50

def extract_lines(bigdict, pattern):
compiled_pattern = re.compile(pattern)
fullnames = bigdict.keys()
fullnames.sort()
filedict = {}
for fullname in fullnames:
title = bigdict[fullname][0]
filedict[fullname] = [title]
text = bigdict[fullname][1]
start = 0
while 1:
match_object = compiled_pattern.search(text, start)
if match_object is None:
break
start, end = match_object.span()
insert = '<font color=red>' + text[start:end] + '</font>'
text2 = text[:start] + insert + text[end:]
lo = max(start - BEFORE, 0)
hi = min(start + len(insert) + AFTER, len(text2))
output = text2[lo:hi].replace('\n', '<br>\n')
filedict[fullname].append(output)
start = end
return filedict

def write_nonce(filename, nonce_file):
lines = open(nonce_file, 'r').readlines()
isthere = 0
for line in lines:
if line.find(filename) != -1:
isthere = 1
break
if not isthere:
head, tail = os.path.split(filename)
line = '<br><a href="%s">%s</a>\n' % (filename, tail)
lines.append(line)
open(nonce_file, 'w').writelines(lines)

def make_html(filedict, topdir):
html_lines = ['<html>', '<head></head>', '<body>']
fullnames = filedict.keys()
fullnames.sort()
for fullname in fullnames:
if len(filedict[fullname]) < 3:
continue
title = filedict[fullname][0]
html_line = '<p><a href="%s">%s</a>\n' % (fullname, title)
html_lines.append(html_line)
html_lines.append('<ul>')
for text in filedict[fullname][1:]:
html_lines.append('<li>')
html_lines.append(text)
html_lines.append('</ul>')
html_lines.append('</body\n</html>\n')
return '\n'.join(html_lines)

if len(sys.argv) != 3:
raise Exception, 'program must have exactly two arguments.'
datafile = sys.argv[1]
pattern = sys.argv[2]

bigdict = cPickle.load(open(datafile, 'r'))
topdir = bigdict[None]
filedict = extract_lines(bigdict, pattern)
html_text = make_html(filedict, topdir)
tail = time.strftime('docs.%Y.%b.%d.%H.%M.%S.html', \
time.gmtime(time.time()))
filename = os.path.join(NONCE_DIR, tail)
open(filename, 'w').write(html_text)
write_nonce(filename, NONCE_FILE)
 
T

Troels Therkelsen

An attempt to produce a complete, alphabetized reference of all of
Python's language features. The purpose is support developers, who
need a quick way to look up information about a language feature.

The table of contents was extracted from:
* the index of the language reference
* the index of the library reference
* the global module index

http://www.ferg.org/pyref/index.html

Very very nice work :)

If I may make a suggestion, it would be to have a letter index for the
Global Module Index as you have for the two other main categories. Or,
alternatively not put each module on its own list. While it is possible to
use the 'find' feature of the browser to access the information, using that
feature still requires that you move your hand away from your mouse. To me,
it would be preferrable to be able to find the module I want in, say, 3-4
clicks, rather than pressing several keys on the keyboard.

Again, great work!

/Troels Therkelsen
 
W

Will Stuyvesant

[Troels Therkelsen]
...To me,
it would be preferrable to be able to find the module I want in, say, 3-4
clicks, rather than pressing several keys on the keyboard....

For me it would be preferrable to use only a few keystrokes instead of
having to find the mouse!
 
A

Aahz

[Troels Therkelsen]
...To me,
it would be preferrable to be able to find the module I want in, say, 3-4
clicks, rather than pressing several keys on the keyboard....

For me it would be preferrable to use only a few keystrokes instead of
having to find the mouse!

That's why you should use Lynx. Then you don't have any options. ;-)
 
W

Will Stuyvesant

[Aahz]
That's why you should use Lynx. Then you don't have any options. ;-)

But isn't Lynx text-only? I want to see the pics! Even though I am
not the kind of pervert that want to do things to them with the mouse.
 
L

Lawrence Oluyede

But isn't Lynx text-only? I want to see the pics! Even though I am
not the kind of pervert that want to do things to them with the mouse.

I think that Lynx in framebuffer should display images too. I'm not
sure because i use Links not Lynx :)
 
M

Mark 'Kamikaze' Hughes

Will Stuyvesant said:
[Aahz]
That's why you should use Lynx. Then you don't have any options. ;-)
But isn't Lynx text-only? I want to see the pics! Even though I am
not the kind of pervert that want to do things to them with the mouse.

Opera can be completely keyboard-driven. And to search, you can type
/TEXT, just like you would in lynx or any other proper viewing or
editing tool.
 
A

Aahz

Will Stuyvesant said:
[Aahz]
That's why you should use Lynx. Then you don't have any options. ;-)

But isn't Lynx text-only? I want to see the pics! Even though I am
not the kind of pervert that want to do things to them with the mouse.

Opera can be completely keyboard-driven. And to search, you can type
/TEXT, just like you would in lynx or any other proper viewing or
editing tool.

Really? That's not in my Opera/Linux 6.1.
 
G

Gabriel Genellina

Really? That's not in my Opera/Linux 6.1.

That really cool feature appeared in v7.20. But Ctrl-F = search in page
works from prehistoric ages :)


Gabriel Genellina
Softlab SRL
 
J

John J. Lee

Gabriel Genellina said:
That really cool feature appeared in v7.20. But Ctrl-F = search in
page works from prehistoric ages :)

Mozilla also has / for incremental search. And most have
ALT-<left arrow> and ALT-<right arrow> for history navigation, and tab,
space and return for other navigation (though I'm never sure if I should
hit tab or return...).


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,196
Latest member
ScottChare

Latest Threads

Top