推荐学习书目
› 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 · Nov 2, 2016 · 8469 views
    This topic created in 3657 days ago, the information mentioned may be changed or developed.

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

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

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

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

    Pycharm 应该是有效的
    hanbaobao2005
    hanbaobao2005
    Nov 3, 2016
    9
    @aristotll 这个算是用到了 pydoc 功能吧?
    7sDream
    7sDream
    Nov 3, 2016❤️2
    10
    ```python
    assert isinstance(x, SomeClass)
    x.abcd # 这里有智能提示
    ```

    在首次定义的时候加一句 assert 可以让 PyCharm 识别类型。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   724 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 19:48 · PVG 03:48 · LAX 11:48 · JFK 14:48
    ♥ Do have faith in what you're doing.