Issue
In http://docs.python.org/library/json.html:
simplejson.load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, use_decimal[, **kw]]]]]]]]])
Deserialize fp (a .read()-supporting file-like object containing a JSON document) to a Python object.
I do know what read()
and write()
do.
But after reading this description "read()-supporting file-like object", I find I don't know what object type supports the read()
and write()
.
And I can't find that in the rest of documentation. Anyone could elaborate more on the statement?
Why I ask this question is for getting "simplejson.load(urllib.open(...))" done.
The return value of "urllib.open(...)" is not a valid object, so I have to tailor it for simplejson. However, it seems like that string is not read()-supporting.
Solution
File-like objects are mainly StringIO
objects, connected sockets and, well, actual file objects.
If everything goes well, urllib.urlopen()
returns a file-like object supporting the necessary methods.
Answered By - ThiefMaster
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.