Reading *.json from URL - json.loads() versus urllib.urlopen.readlines()

Denis McMahon denismfmcmahon at gmail.com
Mon May 27 17:35:22 EDT 2013


On Mon, 27 May 2013 14:29:38 -0700, Bryan Britten wrote:

> Try to not sigh audibly as I ask what I'm sure are two asinine
> questions.
> 
> 1) How is this approach different from twtrDict = [json.loads(line) for
> line in urllib.urlopen(urlStr)]?
> 
> 2) How do I tell how many JSON objects are on each line?

Your code at (1) creates a single list of all the json objects

The code you replied to loaded each object, assumed you did something 
with it, and then over-wrote it with the next one.

As for (2) - either inspection, or errors from the json parser.

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list