loading
 
Small "fix" for Python API
from United States  [214 posts]
13 year
I have been using the Python API with RR and it works beautifully.  However, I noticed what might be a small inconsistency in the ReadAll() function.  I wonder if it should end with the line:

return data

rather than

print data

I tweaked it for my own copy but thought I'd pass along the suggestion.

In the meantime, I wrote a little function to convert the string returned by ReadAll() to a Python dictionary with the variable names as keys and the values as values.  In the function RR stands for my RoboRealm object.  Also, I prepend the string "video_" to the variable names but of course you don't have to do that.

import re

def ReadAll(self):
    response = self.RR.ReadAll()
    response = re.sub("(<response>)|(</response>)", "", response)
    values = re.findall("<(?P<VAR>.+)>(.+)</(?P=VAR)>", response)
    data = dict({})
    for key, value in values:
        key = "video_" + key
        data[key] = value
    return data

--patrick

http://www.pirobot.org
Anonymous 13 year
Patrick,

Nice! We've added that as a separate routine (just to avoid breaking anyones existing code) by adding that as GetAllVariables which is a nice addition to the API. Its now part of the Python API file.

Thanks very much!
STeven.
from United States  [214 posts] 13 year
Cool--I'm honored!

--patrick

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index