Google Python Style Guide - V2EX
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
soulhacker
V2EX    Python

Google Python Style Guide

  •  
  •   soulhacker
    neolee 2012-04-19 15:57:06 +08:00 6020 次点击
    这是一个创建于 4924 天前的主题,其中的信息可能已经有所发展或是发生改变。
    16 条回复    1970-01-01 08:00:00 +08:00
    ayanamist
        1
    ayanamist  
       2012-04-19 19:18:15 +08:00
    禁用了所有Python的magic特性是亮点
    lackrp
        2
    lackrp  
       2012-04-19 21:28:43 +08:00
    @ayanamist 什么是magic特性啊?望不吝赐教
    tioover
        3
    tioover  
       2012-04-19 21:57:39 +08:00
    @lackrp
    @ayanamist
    **kwargs & *args 算不算
    gastlygem
        4
    gastlygem  
       2012-04-20 10:00:04 +08:00
    @ayanamist 神马是 magic 特性?我只知道类的保留方法函数被称为 magic method,就是带双下划线,用来实现类的特殊功能的那种. 比如 __add__, __lt__。

    参考:http://www.rafekettler.com/magicmethods.html

    这个文档只是不让你使用长得像 magic method 的 method 名称,例如 __mymethod__ 之类,以防和真正的 magic method 混淆,影响代码可读性。

    @lackrp

    @tioover 不算。
    bhuztez
        5
    bhuztez  
       2012-04-20 10:05:19 +08:00
    @gastlygem magic method 相当于是协议,你需要用的时候还是逃不掉的。比如 pickle 就定义了好几个呢。
    tioover
        6
    tioover  
       2012-04-20 10:05:57 +08:00 via Android
    @gastlygem pylint说算,还扣分………
    gastlygem
        7
    gastlygem  
       2012-04-20 10:25:58 +08:00
    @bhuztez 那倒是。不过文档说的意思是不要用下面的方式给普通 method 命名,因为它们是被 Python 保留的。

    __double_leading_and_trailing_underscore__ names (reserved by Python)

    @tioover PyLint 就别提了吧,默认配置各种warning……
    ayanamist
        8
    ayanamist  
       2012-04-20 10:30:01 +08:00
    vicalloy
        9
    vicalloy  
       2012-04-20 10:31:25 +08:00
    PyLint默认配置warning实在太多,没注释啥的都warning。
    要用还真需要认真配置一番。
    同事翻译了这文章的中文版
    http://codinn.com/projects/google-python-style-guide/view/
    gastlygem
        10
    gastlygem  
       2012-04-20 11:30:02 +08:00
    @ayanamist 晕,不是没仔细看,而是没人把这些叫做“magic 特性”。
    ayanamist
        11
    ayanamist  
       2012-04-20 11:31:55 +08:00
    @gastlygem 那应该叫什么?
    felinx
        12
    felinx  
       2012-04-20 11:34:49 +08:00
    基本按照pep8来,除了个别写sql的超过80个字符。
    gastlygem
        13
    gastlygem  
       2012-04-20 12:43:52 +08:00
    @ayanamist 嗯,俺又想了想,这些花哨的高级功能其实叫 magic 可以,不过毕竟也没有一个约定俗成词专门来称呼,提到时还是加个解释比较好 :)
    ayanamist
        14
    ayanamist  
       2012-04-20 12:45:42 +08:00
    @gastlygem 不都是把Ruby里这些花里胡哨的东西称为magic么……
    reus
        15
    reus  
       2012-04-20 12:50:46 +08:00
    @ayanamist ruby鼓励这种方式所以以magic褒之,python不鼓励所以也没人把这些叫magic
    ayanamist
        16
    ayanamist  
       2012-04-20 14:16:42 +08:00
    @reus dark magic也是magic嘛
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2732 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 08:31 PVG 16:31 LAX 01:31 JFK 04:31
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86