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

Python 练习册,每天一个小程序 :-)

  •  1
     
  •   xiaowangge ·
    Yixiaohan · Dec 16, 2014 · 7675 views
    This topic created in 4345 days ago, the information mentioned may be changed or developed.
    欢迎大家 Pull Request 出题目,贴代码(Gist、Blog皆可):-)

    题目:
    https://github.com/Yixiaohan/show-me-the-code

    参考代码:
    https://github.com/Show-Me-the-Code/python
    11 replies  •  2015-01-11 20:28:59 +08:00
    jookr
    jookr
    Dec 16, 2014
    1
    大神 能否指点一下,我昨天刚入门
    正则截取内容不会
    下面这个例子 我需要截取"啊啊啊"这个内容出来怎么获取不到呢

    import re
    html = 'www啊啊啊,呵呵,哈哈,嘿嘿'
    counts = re.findall(r'"www(.*),呵呵,哈哈,嘿嘿', html)

    print counts[1]

    raw_input()
    realityone
    realityone
    Dec 16, 2014❤️1
    2
    @jookr 刚入门哪有这么跳内容的。。
    counts = re.findall(r'www(.*)', html)
    正则入门吧。。
    jookr
    jookr
    Dec 16, 2014
    3
    中文的逗号匹配结尾会提示错误怎么办
    jookr
    jookr
    Dec 16, 2014
    4
    @realityone 谢谢
    但是你的代码会获取整个www后面的内容,不能只截取出"啊啊啊"

    import re
    html = 'www啊啊啊,呵呵,哈哈,嘿嘿'
    #counts = re.findall(r'"www(.*),呵呵,哈哈,嘿嘿', html)
    counts = re.findall(r'www(.*)', html)
    get_content = counts[0]

    print get_content.decode('utf-8').encode('cp936')
    jookr
    jookr
    Dec 16, 2014
    5
    自己解决了


    # -*- coding: utf-8 -*-


    import re
    html = 'www啊啊啊,呵呵,哈哈,嘿嘿'
    #counts = re.findall(r'"www(.*),呵呵,哈哈,嘿嘿', html)
    counts = re.findall(r'www(.*?),(.*?),(.*?),', html)
    get_content = counts[0]

    #print get_content

    for i in get_content:
    print i.decode('utf-8').encode('cp936')
    Bitex
    Bitex
    Dec 16, 2014
    6
    @jookr

    count = re.findall(r'www(.*?),', html)

    既然已经用了非贪婪匹配,就没必要把后面的全加上了
    Bitex
    Bitex
    Dec 16, 2014
    7
    @jookr

    count = re.findall(r'www([^,]*?),', html)

    应该是这样……上面打错了。

    没用过Python3,不知道[^,]这种写法有没有问题
    0x5e
    0x5e
    Dec 16, 2014
    8
    @realityone 哟西,好巧:-)
    R4rvZ6agNVWr56V0
    R4rvZ6agNVWr56V0
    Dec 17, 2014
    9
    fun
    4everLoveU
    4everLoveU
    Dec 19, 2014
    10
    好东西,不错,支持一下!
    mingyun
    mingyun
    Jan 11, 2015
    11
    star
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4633 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 08:49 · PVG 16:49 · LAX 00:49 · JFK 03:49
    ♥ Do have faith in what you're doing.