推荐学习书目
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
lsj5031
V2EX  ›  Python

PEP435加入了Enum支持……我就问下我们为什么需要Enum?有哪些典型的应用场景?

  •  
  •   lsj5031 · Sep 28, 2013 · 3887 views
    This topic created in 4612 days ago, the information mentioned may be changed or developed.
    8 replies    1970-01-01 08:00:00 +08:00
    11
        1
    11  
       Sep 28, 2013
    比如,出现 typo 的时候。
    humiaozuzu
        2
    humiaozuzu  
       Sep 28, 2013 via iPhone
    函数多种返回结果的时候
    miaoever
        3
    miaoever  
       Sep 28, 2013
    比如写自动机需要定义各种状态的时候。
    lsj5031
        4
    lsj5031  
    OP
       Sep 28, 2013
    @humiaozuzu
    @miaoever
    之前用tuple或者dict甚至自定义的class不也挺方便吗?
    humiaozuzu
        5
    humiaozuzu  
       Sep 28, 2013
    @lsj5031 dict 可以,不过语法真的不爽,目前都是用的 class 实现的,不过有 native 的方法更好吧
    BOYPT
        6
    BOYPT  
       Sep 28, 2013
    以往很多pythoner认为不需要ENUM特性,哈哈哈
    zhujinliang
        7
    zhujinliang  
       Sep 29, 2013
    以前
    bool DoSomething()
    {
    ...
    }

    接触C#多了以后:
    enum DoSomethingResult
    {
    Success,
    Failed
    }
    DoSomethingResult DoSomething()
    {
    ...
    }
    Ricepig
        8
    Ricepig  
       Sep 30, 2013 via iPhone
    @zhujinliang 当出现第三种返回状态时,enum就显得方便了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2944 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 352ms · UTC 13:20 · PVG 21:20 · LAX 06:20 · JFK 09:20
    ♥ Do have faith in what you're doing.