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

有什么优雅的方法把正则解析后的文本变为其他数据类型?

  •  
  •   smdbh · May 10, 2018 · 3737 views
    This topic created in 3061 days ago, the information mentioned may be changed or developed.
    例如经过正则匹配后,用 dictgroup 得到一个 dict 数据结构,其中的 key 和 val 都是文本,但实际某些 key 需要的是 int 或是 float 的数据类型。除了把他们读出来手动改完写回去,还有其他方法么
    5 replies  •  2018-05-10 14:31:08 +08:00
    crb912
        1
    crb912  
       May 10, 2018 via Android
    从正则的结果中取出你要的 key,假设是 temp,强制转换一下不可以么? int(temp)。
    python 中的 int 是类,允许从字符串转到 int,不同于 c/cpp
    Leigg
        2
    Leigg  
       May 10, 2018 via Android
    python 中的 map 函数了解一下
    awakn123
        3
    awakn123  
       May 10, 2018
    都数据类型了,不说什么语言真的好么
    xxxy
        4
    xxxy  
       May 10, 2018
    python 中的列表推导
    jmc891205
        5
    jmc891205  
       May 10, 2018
    一些 key 需要是 int 或 float 另一些保持文本?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   934 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 19:07 · PVG 03:07 · LAX 12:07 · JFK 15:07
    ♥ Do have faith in what you're doing.