What is a file object in Python?

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 (aread () is a supporting file object containing a JSON document) for the Python object.

I know what they are doing read()and write().

But after reading this description of "read () - supporting a file object", I believe that I do not know what type of object supports read()and write().

And I cannot find this in the rest of the documentation. Could someone please elaborate on this statement?

Why am I asking this question to get "simplejson.load (urllib.open (...))". The return value of "urllib.open (...)" is not a valid object, so I have to adapt it for simplejson. However, it looks like the line is not being read () - supports.

+5
source share
2 answers

file objects are basically objects StringIOconnected by sockets, etc ... the actual file objects. If everything goes well, it urllib.urlopen()also returns a file-like object that supports the necessary methods.

+5
source

simplejson has load calls and dumps that consume and produce strings instead of file objects.

StringIO simplejson .

http://svn.red-bean.com/bob/simplejson/tags/simplejson-1.3/docs/index.html

+1

All Articles