On Wed, Dec 23, 2015 at 7:36 PM, Ben Finney <[email protected]> wrote:
> So how do I get from a Python 2 ‘file’ object, to whatever
> ‘io.TextIOWrapper’ wants?
I would dup the file descriptor and close the original file. Then open
the file descriptor using io.open:
>>> p = subprocess.Popen(['uname'], stdout=subprocess.PIPE)
>>> fd = os.dup(p.stdout.fileno())
>>> fd
4
>>> p.stdout.close()
>>> fout = io.open(fd, 'r')
>>> fout
<_io.TextIOWrapper name=4 encoding='UTF-8'>
>>> fout.read()
u'Linux\n'
--
https://mail.python.org/mailman/listinfo/python-list