我有以下代码:
>>> import io
>>> b = io.BytesIO(b"Hello World")
>>> f = io.TextIOWrapper(b)
>>> f.fileno()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
io.UnsupportedOperation: fileno
Run Code Online (Sandbox Code Playgroud)
但是,当我加载文件时,有一个fileno属性:
>>> f = open("test.py")
>>> f.fileno()
3
Run Code Online (Sandbox Code Playgroud)
有没有办法fileno为第一种情况创建属性,即我将BytesIO对象强制转换为TextIOWrapper对象?