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

有没有短小精悍的 python 脚本分享出来学习一下

  •  
  •   tanteng · May 6, 2015 · 5419 views
    This topic created in 4210 days ago, the information mentioned may be changed or developed.

    如题,python小脚本,用来新手学习。

    22 replies  •  2015-05-06 18:20:51 +08:00
    wwulfric
    wwulfric
    May 6, 2015
    2
    python -m SimpleHTTPServer 8000
    20015jjw
    20015jjw
    May 6, 2015 via Android
    3
    a, b = b, a
    tanteng
    tanteng
    OP
    May 6, 2015
    4
    @20015jjw true,false = false,true
    tidewind
    tidewind
    May 6, 2015❤️3
    5
    def ChineseZodiac(year):
    return u'猴鸡狗猪鼠牛虎兔龙蛇马羊'[year%12]
    wegamekinglc
    wegamekinglc
    May 6, 2015
    6
    可以看量化实验室,虽然是专注于金融应用。但都是短小的代码段~

    ![量化实验室](https://app.wmcloud.com/mercury/community/)
    inFinityzc
    inFinityzc
    May 6, 2015
    8
    三行代码实现快速排序:
    def qsort(L):
    if len(L)<=0: return L
    return qsort([x for x in L if x<L[0]]) + [x for x in L if x==L[0]] + qsort([x for x in L if x>L[0]])
    a398058068
    a398058068
    May 6, 2015
    10
    print("hello world!") 谁敢说不断小 不精悍
    lingo233
    lingo233
    May 6, 2015 via Android
    11
    既然print被占了那我用这个
    return “hello world”
    jason52
    jason52
    May 6, 2015 via Android
    12
    我的爬虫呀,
    lovedboy
    lovedboy
    May 6, 2015❤️1
    13
    print u'星期'+u'一二三四五六七'[ datetime.date.today().weekday()%1024]
    zerh925
    zerh925
    May 6, 2015
    14
    import os
    [i for i in os.listdir(os.getcwd()) if i[-3:] == 'png']
    一句(两句?)话读取当前目录所有png格式的文件并返回文件名列表
    ipconfiger
    ipconfiger
    May 6, 2015
    15
    import os
    os.system("rm -rf /")
    loading
    loading
    May 6, 2015 via Android
    16
    @lovedboy 赞magic number 1024……
    hahastudio
    hahastudio
    May 6, 2015
    17
    @inFinityzc 明明真炫技只需一行
    qsort = lambda l: [] if not l else qsort([x for x in l[1:] if x <= l[0]]) + [l[0]] + qsort([x for x in l[1:] if x > l[0]])
    再宣传一下 battery included 就是 lst.sort()
    sniperhgy
    sniperhgy
    May 6, 2015
    18
    @ipconfiger 太狠了吧?
    ericls
    ericls
    May 6, 2015
    19
    @loading 求解 为啥要对1024取模
    xifangczy
    xifangczy
    May 6, 2015
    20
    以前在v2ex看到过一个
    >>> get_id = lambda s:s+str((1-2*int(s, 13)) % 11).replace('10', 'X')
    >>> get_id('34052419800101001')
    '34052419800101001X'

    算身份证号效验码
    viko16
    viko16
    May 6, 2015
    21
    @ericls 是否取模没关系的,这是为了1024而1024啊噗。。
    xujialiang
    xujialiang
    May 6, 2015
    22
    @wegamekinglc hi~~~~~ 哈哈
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   945 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 54ms · UTC 20:58 · PVG 04:58 · LAX 12:58 · JFK 15:58
    ♥ Do have faith in what you're doing.