- Continuing to work on a python code completion engine. Phil helped me with some ideas and pointed out a few built in introspection methods in Python.
- Built something basically using the existing visibility script engine to run “info” on the variable in question and a problem arose:
- For example, say your cursor is at the end of this script:
- def solrXmlFromListList(doc, root, headers, table):
for row in table:
rowNode = doc.createElement(‘doc’)
root.appendChild(rowNode)
for i in xrange(len(headers)):
fieldNode = doc.createElement(‘field’)
fieldNode.setAttribute(‘name’, headers[i])
textNode = doc.createTextNode(str(row[i]))
fieldNode. - I can’t run info on ‘fieldNode’ without appending info(fieldNode) to the end of the script and executing the entire script which is obviously not an option
- So basically I need to find a way to run introspection on a script without running any of the script

I think I wrote the scripting app so that you can run multiple scripts without them interfering with each other. As such, I think you might be able to add a java method that behaves like runScript(String script) but it’s introspectThis(String fragment), that would run your introspection script and return the value through Flex to an “introspectionHandler()” or something like that?
There’s several issues with executing part of a script:
1. If it writes something to the database it could have ill effects
2. Some scripts take awhile to execute so waiting even 10 seconds for auto complete suggestions isn’t fun
3. The script could throw an error because it’s incomplete or simply because there is an error in it somewhere
My experience is that the system really only hangs the first time any Python script is run. After that things seem to be loaded. The script that I’m thinking you’d run for introspection would be something real minimal; e.g.
——————————————————–
def info(object, spacing=10, collapse=1):
# Print methods and doc strings.
# Takes module, class, list, dictionary, or string.
print “Type: “+str(type(object))
for method in dir(object):
methodStr = str(method)
infoList = []
argStr = “”
commentStr = “”
if callable:
infoList = str(getattr(object, method).__doc__).split(‘n’)
argStr = infoList[0]
#commentStr = infoList[2]
if not(methodStr.startswith(“__”)):
print “————–nmethod:”+methodStr+”ntargs: “+argStr
“””
methodList = [method for method in dir(object) if callable(getattr(object, method))]
processFunc = collapse and (lambda s: ” “.join(s.split())) or (lambda s: s)
print “n”.join([“%s %s” %
(method.ljust(spacing),
processFunc(str(getattr(object, method).__doc__)))
for method in methodList])
“””
li = “foo”
info(li)
——————————————————–
And you pass in whatever object you want to know about.
The problems that I see with this kind of approach is that you have to pull out the instantiation code for whatever you want to introspect. That could be a show-stopper, but I haven’t played with the concept to know one way or the other.
Thoughts?