Python Forum

Full Version: creating a dummy file object
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i want to create a file object that any attempt to write just drops the data, never calling the system, and any attempt to read gets no data and simulates an end of file, never calling the system, working like "/dev/null" does on Unix/Linux. is an object with functions read() and write() doing the appropriate things and a dummy close() sufficient?
It may suffice in many cases, however if you want a more robust implementation, you could subclass the abstract base classes of module io and implement their stub methods instead.