Mike 8.19.2010

  • 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’)
      for i in xrange(len(headers)):
      fieldNode = doc.createElement(‘field’)
      fieldNode.setAttribute(‘name’, headers[i])
      textNode = doc.createTextNode(str(row[i]))
    • 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

3 thoughts on “Mike 8.19.2010

  1. phil.feldman Post author

    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?

  2. mike.kluever Post author

    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

  3. phil.feldman Post author

    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” %
    processFunc(str(getattr(object, method).__doc__)))
    for method in methodList])

    li = “foo”


    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.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.