V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2017-11-07 15:50:00 +08:00 · 3540 次点击
    这是一个创建于 2362 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在 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 条回复    2017-11-08 16:12:20 +08:00
    misaka19000
        1
    misaka19000  
       2017-11-07 15:56:17 +08:00
    动态类型没法确定
    zjsxwc
        2
    zjsxwc  
       2017-11-07 16:44:17 +08:00
    zjsxwc
        3
    zjsxwc  
       2017-11-07 16:54:19 +08:00   ❤️ 1
    或者和大家一样用都注释来 表示类型帮助 ide 推导: https://github.com/requests/requests/blob/master/requests/api.py#L64
    cxbig
        4
    cxbig  
       2017-11-07 17:51:26 +08:00
    添加注释,指定对象类型。
    introom
        5
    introom  
       2017-11-07 17:59:33 +08:00
    还是干脆放弃,这个已经是折腾了。
    xlui
        6
    xlui  
       2017-11-07 18:02:29 +08:00
    <img src="https://i.loli.net/2017/11/07/5a018487119cc.png" alt="1.png" title="1.png" />
    xlui
        7
    xlui  
       2017-11-07 18:03:43 +08:00   ❤️ 1
    wcsjtu
        8
    wcsjtu  
       2017-11-07 18:32:12 +08:00
    用 visual studio + ptvs
    跑几次你的代码,你会发现 ide 竟然可以自动补全动态类型了。一定要跑几次~~
    iamjjh
        9
    iamjjh  
    OP
       2017-11-08 16:12:20 +08:00
    @xlui 多谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2659 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 02:03 · PVG 10:03 · LAX 19:03 · JFK 22:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.