I'm attempting to read the result of an API call via Python and I'm using a base application / script as a starting point.
I'm a bit confused at the one point in the script where the reading occurs:
result=urllib2.urlopen.read()[13:-1]
if result=="true":
logging.info('available')
My question specifically deals with the 13:-1
. Per the Python documentation, it appears to be an offset or starting point for the application to read. Here is an example given:
>>> f.seek(-3, 2) # Go to the 3rd byte before the end
This looks slightly different from the .read()
in my script as the delimiter in mine is a :
rather than a ,
.
And to clarify what it is reading, I'm using the Ello API as an example. So it would read a link that generates results that look like this:
{
available: true,
suggestions: [
"crunchyfeelsfists",
"crunchy_nicksshakes",
"supercrunchy"
]
}
So the example script I'm using is reading the "available: true" line.
My first question is, what is the difference between using the :
and ,
. My next question would be is how is the 13:-1
reading the second line of that API result?
Any help would be appreciated!