推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
acone2003
V2EX  ›  Python

Python 2.X 的 types.FileType 如何移植到 Python 3.X?

  •  
  •   acone2003 · Nov 19, 2018 · 2902 views
    This topic created in 2730 days ago, the information mentioned may be changed or developed.
    最近下载了一个 parallel python ( PP )模块,是在 python 2 下运行的,现在想移植到 python 3 中,有很多地方需要修改,其中有一个地方不知道怎么改了,望各位不吝给予帮助:
    pptransport.py 中有一句:
    import types
    if isinstance(r, types.FileType) and isinstance(w, types.FileType):
    self.r = r
    self.w = w
    查了一下在 python 3 中已没有了 FileType 属性,该怎么办?
    4 replies    2018-11-20 09:02:19 +08:00
    no1xsyzy
        1
    no1xsyzy  
       Nov 19, 2018
    https://docs.python.org/2/library/types.html?highlight=types%20filetype#types.FileType
    > types.FileType
    > The type of open file objects such as sys.stdout; alias of the built-in file.

    >>> type(sys.stdout)
    <class '_io.TextIOWrapper'>
    daiqiangbudainiu
        2
    daiqiangbudainiu  
       Nov 19, 2018
    查了一下,pip install filetype 还是有的,而且文档中给了用法
    chenstack
        3
    chenstack  
       Nov 19, 2018
    试了一下,可以用 io.IOBase 判断
    from io import IOBase
    isinstance(r, IOBase)
    acone2003
        4
    acone2003  
    OP
       Nov 20, 2018
    谢谢 chenstack,OK!同时也谢谢楼上两位!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   977 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 20:35 · PVG 04:35 · LAX 13:35 · JFK 16:35
    ♥ Do have faith in what you're doing.