On 05/27/2015 10:29 PM, Marko Rauhamaa wrote:
Ben Finney <ben+pyt...@benfinney.id.au>:

It seems the existing ‘open’ implementation doesn't allow you to
override the type of object returned.
The question is, can you assign to the builtin namespace. I'm guessing
you can't.

Of course you can.

Python2:
>>> __builtins__.open = "whatever"
>>>

Python3:
>>> import builtins
>>> builtins.open = "whatever"
>>>

Of course doing so is like shooting yourself in the foot: Any subsequent pain is your own fault and probably well deserved.

Gary Herron




Within a module, you can simply do:

    open = MyFile

Also, in other modules, you can:

    from myfile import open


Marko


--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418


--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to