V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
iamjjh
V2EX  ›  Python

求教 pycharm 代码自动补全的问题

  •  
  •   iamjjh · Nov 7, 2017 · 4358 views
    This topic created in 3098 days ago, the information mentioned may be changed or developed.

    在 pycharm 中使用 with 语句没有自动补全的提示

    from urllib import request
    
    with request.urlopen('https://api.douban.com/v2/book/2129650') as f:
    

    想调用f.read()方法,但是没有自动补全提示

    在论坛搜索下,需要使用assert isinstance()一下f

    请问如何确定 f 的类型?

    9 replies    2017-11-08 16:12:20 +08:00
    misaka19000
        1
    misaka19000  
       Nov 7, 2017
    动态类型没法确定
    zjsxwc
        2
    zjsxwc  
       Nov 7, 2017
    zjsxwc
        3
    zjsxwc  
       Nov 7, 2017   ❤️ 1
    或者和大家一样用都注释来 表示类型帮助 ide 推导: https://github.com/requests/requests/blob/master/requests/api.py#L64
    cxbig
        4
    cxbig  
       Nov 7, 2017
    添加注释,指定对象类型。
    introom
        5
    introom  
       Nov 7, 2017
    还是干脆放弃,这个已经是折腾了。
    akiakiseofficial
        6
    akiakiseofficial  
       Nov 7, 2017
    <img src="https://i.loli.net/2017/11/07/5a018487119cc.png" alt="1.png" title="1.png" />
    wcsjtu
        8
    wcsjtu  
       Nov 7, 2017
    用 visual studio + ptvs
    跑几次你的代码,你会发现 ide 竟然可以自动补全动态类型了。一定要跑几次~~
    iamjjh
        9
    iamjjh  
    OP
       Nov 8, 2017
    @xlui 多谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2351 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 05:05 · PVG 13:05 · LAX 22:05 · JFK 01:05
    ♥ Do have faith in what you're doing.