Returning a custom file object (Python 3)

Ben Finney ben+python at benfinney.id.au
Wed May 27 22:40:53 EDT 2015


Ben Finney <ben+python at benfinney.id.au> writes:

> Steven D'Aprano <steve at pearwood.info> writes:
>
> > but how do I tell open() to use MyFile?
>
> I haven't used it, but does the ‘opener’ parameter do what you want?

No, it doesn't; the ‘opener’ parameter doesn't have any say in the type
of object returned from ‘open’.

It seems the existing ‘open’ implementation doesn't allow you to
override the type of object returned. You may have to resort to
monkey-patching the ‘io’ attributes to put your preferred classes there.

-- 
 \       “Science shows that belief in God is not only obsolete. It is |
  `\                        also incoherent.” —Victor J. Stenger, 2001 |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list