What is exactly a file-like object in Python?

后端 未结 4 1698
说谎
说谎 2020-12-31 03:15

In http://docs.python.org/library/json.html:

simplejson.load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_

4条回答
  •  耶瑟儿~
    2020-12-31 03:38

    From the glossary:

    file-like object

    A synonym for file object

    and a file object is

    file object

    An object exposing a file-oriented API (with methods such as read() or write()) to an underlying resource. Depending on the way it was created, a file object can mediate access to a real on-disk file or to another type of storage or communication device (for example standard input/output, in-memory buffers, sockets, pipes, etc.). File objects are also called file-like objects or streams.

    There are actually three categories of file objects: raw binary files, buffered binary files and text files. Their interfaces are defined in the io module. The canonical way to create a file object is by using the open() function.

提交回复
热议问题