Displays docstrings of attributes of the given Python module on a web browser. Drop it into the cgi-bin of your web-server, and access it like this, for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import cgi
import cgitb; cgitb.enable()
write = cgi.sys.stdout.write
write('Content-Type: text/html\n\n')
form = cgi.FieldStorage()
module = form.getfirst('m')
write('<head><title> %s </title></head>' % module)
try:
mod = __import__(module)
except:
write('<b> Could not import module named %s <br><br> Usage: http://%s%s?m=moduleName</b>' % (module, cgi.os.environ['server_name'],
cgi.os.environ['script_name']))
cgi.sys.exit()
write('<table border="0" bgcolor="#707070" cellpadding="4" cellspacing="2" width="800" align="center">')
write('<th colspan="2" bgcolor="#E0E0E0"> <h1> Python %s module attributes and their doc strings </h1></th>' % module)
for attr in dir(mod):
try:
write('''
<tr bgcolor="#FFFFFF">
<td>%s</td>
<td>%s</td>
</tr>
''' % (attr, getattr(mod, attr).__doc__.replace('\n','<br>')))
except:
pass
write('</table>')
|
Tags: dosctring, python_developer_tools