What is the minimal subset of file methods I need to implement to get the full python file interface? -


Python has a wonderful module, allowing you to implement a full dict. (For example)) What is the same thing for the file interface in Python with a minimum set of methods? If not, what would you recommend as a minimum set of methods for implementing a file -like object for duck-typing purposes?

And how you will deal with things is to use your file as an object in a with statement, as if you can do it with a regular file, or that Want to iterate (like you can make a regular file) or call it readline or readlines and it's something intelligent and useful (like Can you do with a regular file)? Do you have to implement them all? Or what are the better options?

I know that I can bring every one of these hands in my hand but the archive interface should only give me __ , < Code> __ iter __ , __set __ , and __getitem __ . I get pop , popitem , clear , update , setdefault , Is, __ contains the , key , item , value , , , __eq __ , and ___ __ free for everyone. There is a minimal interface for defining __ dict __ , and if I apply it, then I get the full dict interface, all additional methods are applied as per the minimum interfaces. Is being done

Similarly, I would like to know what is the minimum interface for file that I have to implement to get the full interface. __ entered __ , __ exit__, , readline , readlines , __ iter __ Is a way to get and next if I just implement read , write and close , Or do I have to apply everything to myself? Every time I want the full file interface?

statement requires a context manager:

< P> The file type is fully defined:

looks very simple.

The document lists the methods and attributes of a file and a reference manager. Apply them

Why do you need more information?

If you want to work in all ways, then you have to implement all the methods. Contrary to the collection, there is no abstract base class for files.

Comments