-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntrospect.py
More file actions
31 lines (26 loc) · 1.26 KB
/
Copy pathIntrospect.py
File metadata and controls
31 lines (26 loc) · 1.26 KB
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
from ExamplePage import ExamplePage
class Introspect(ExamplePage):
def writeContent(self):
self.writeln('<h4>Introspection</h4>')
self.writeln("<p>The following table shows the values for various"
" Python expressions, all of which are related to <em>introspection</em>."
" That is to say, all the expressions examine the environment such as"
" the object, the object's class, the module and so on.</p>")
self.writeln('<table align="center" bgcolor="#EEEEFF" border="0"'
' cellpadding="2" cellspacing="2" width="100%">')
self.pair('locals().keys()', locals().keys())
self.list('globals().keys()')
self.list('dir(self)')
self.list('dir(self.__class__)')
self.list('self.__class__.__bases__')
self.list('dir(self.__class__.__bases__[0])')
self.writeln('</table>')
def pair(self, key, value):
if isinstance(value, (list, tuple)):
value = ', '.join(map(str, value))
self.writeln('<tr valign="top"><td>%s</td><td>%s</td></tr>'
% (key, self.htmlEncode(str(value))))
def list(self, codeString):
value = eval(codeString)
assert isinstance(value, (list, tuple))
self.pair(codeString, value)