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
Boristype000
V2EX  ›  Python

python 让 ide(如 Pycharm) 在函数内部能自动补全变量的方法有哪些?

  •  
  •   Boristype000 · 2016-11-02 23:11:17 +08:00 · 7193 次点击
    这是一个创建于 2724 天前的主题,其中的信息可能已经有所发展或是发生改变。

    暂时知道的有能让形参补全的方法就是

    def my_fun(x:int,y:int):
    	z = 1
        return z
    

    可是这样只能自动识别形参,函数内部的临时变量如 z 却不能自动补全,这对于要使用大型库的 Coder 来说很容易出错啊。。

    10 条回复    2016-11-03 15:38:54 +08:00
    Trim21
        1
    Trim21  
       2016-11-02 23:14:37 +08:00
    函数内部的临时变量为什么要进行自动补全呢......这个东西不是应该不暴露出来的吗?
    Boristype000
        2
    Boristype000  
    OP
       2016-11-02 23:19:24 +08:00
    @Trim21 可是写那些新的大库的工作流的函数。。难道都是用 ipython 这样写出来的吗
    zhuangzhuang1988
        3
    zhuangzhuang1988  
       2016-11-02 23:35:33 +08:00
    没看懂要干嘛, z 的话应该已经识别类型的了
    alexapollo
        4
    alexapollo  
       2016-11-02 23:37:13 +08:00
    Scala 大法好
    cszhiyue
        5
    cszhiyue  
       2016-11-03 01:33:24 +08:00 via Android
    编译型思路写脚本语言。一般通过 docstrings 说明
    nicegoing
        6
    nicegoing  
       2016-11-03 08:42:05 +08:00 via iPhone
    写了 python 才知道为啥脚本语言要经常百度 Google 查函数
    laoyur
        7
    laoyur  
       2016-11-03 09:16:35 +08:00   ❤️ 1
    def my_fun(x, y):
    """
    :type x: int
    :type y: int
    """
    z = 1
    """
    :type z: int
    """
    return z
    aristotll
        8
    aristotll  
       2016-11-03 11:22:15 +08:00   ❤️ 1
    def my_fun(x, y):
    """
    :type x: int
    :type y: int
    """
    z = 1 #type: int
    return z

    Pycharm 应该是有效的
    hanbaobao2005
        9
    hanbaobao2005  
       2016-11-03 13:54:42 +08:00
    @aristotll 这个算是用到了 pydoc 功能吧?
    7sDream
        10
    7sDream  
       2016-11-03 15:38:54 +08:00   ❤️ 2
    ```python
    assert isinstance(x, SomeClass)
    x.abcd # 这里有智能提示
    ```

    在首次定义的时候加一句 assert 可以让 PyCharm 识别类型。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2832 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 13:54 · PVG 21:54 · LAX 06:54 · JFK 09:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.