被 Python 的语法缩进搞晕了。大家有啥好点的方法处理缩进不? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
meteor2013

被 Python 的语法缩进搞晕了。大家有啥好点的方法处理缩进不?

  •  
  •   meteor2013 Sep 6, 2014 6082 views
    This topic created in 4264 days ago, the information mentioned may be changed or developed.
    我在sublime中写的代码。

    for num in range(10,20): #to iterate between 10 to 20
    for i in range(2,num): #to iterate on the factors of the number
    if num%i == 0: #to determine the first factor
    j=num/i #to calculate the second factor
    print '%d equals %d * %d' % (num,i,j)
    break #to move to the next number, the #first FOR
    else: # else part of the loop
    print num, 'is a prime number'
    24 replies    2014-10-14 14:07:26 +08:00
    meteor2013
        1
    meteor2013  
    OP
       Sep 6, 2014
    代码拷贝进来全乱了,大家将就看
    P9
        2
    P9  
       Sep 6, 2014
    4个空格换一个tab 设置好就行了把
    9hills
        3
    9hills  
       Sep 6, 2014
    Pycharm自动格式化,有些人适合IDE,有些人适合编辑器。。

    lz你还是IDE吧
    zjgsamuel
        4
    zjgsamuel  
       Sep 6, 2014
    sublime 中不是有python 的语法检查和 代码格式化的插件么?
    ivanlw
        5
    ivanlw  
       Sep 6, 2014   2
    缩进是代码逻辑清晰的基本功了,您还是贴gist吧,这酸爽,直接看不下去了
    nicai000
        6
    nicai000  
       Sep 6, 2014
    你讨论缩进问题, 结果缩进全没了还让我们凑合着看? 这逻辑, 就别Python了, Python对代码逻辑清晰要求太高.
    xiaowangge
        7
    xiaowangge  
       Sep 6, 2014 via Android
    请下载 PyCharm 免费版本。(^_^)
    zoosucker
        8
    zoosucker  
       Sep 6, 2014
    使用空格缩进好了。
    yangff
        9
    yangff  
       Sep 6, 2014 via Android   1
    用Ruby
    heliumhgy
        10
    heliumhgy  
       Sep 6, 2014
    emacs 大法好
    limuxy
        11
    limuxy  
       Sep 6, 2014 via Android
    Sublime设置里改一下 把缩进改成4个空格
    Delbert
        12
    Delbert  
       Sep 6, 2014
    贴gist吧,是在看不懂了……
    或者把Tab直接换成2/4个空格........
    meteor013
        13
    meteor2013  
    OP
       Sep 6, 2014
    @P9
    @ivanlw
    @zjgsamuel
    @xiaowangge
    @zoosucker
    @yangff
    @heliumhgy
    @limuxy
    @Delbert


    谢大家,

    把Sublime设置里了一下4格,
    感觉现在

    效率高多了。。。
    stackpop
        14
    stackpop  
       Sep 6, 2014
    pep8
    ToughGuy
        15
    ToughGuy  
       Sep 6, 2014
    从学python到现在没哦与遇到过缩进问题....

    给编辑器装个PEP8插件吧....

    Pylint或Pyflakes
    lizhijun
        16
    lizhijun  
       Sep 6, 2014
    vim
    ipconfiger
        17
    ipconfiger  
       Sep 6, 2014
    写代码是一回事,贴代码是另外一回事,写代码好的编辑器和IDE都可以解决这个问题,贴代码用gist。
    guoguoer
        18
    guoguoer  
       Sep 6, 2014 via Android
    好像注释有点多,代码清晰,简单的部分就不用注释了。
    youyongsong
        19
    youyongsong  
       Sep 6, 2014
    除了将TAB设置为4个空格外,View->Indentation->Convert Indentation to Tabs也是不错的
    heliar
        20
    heliar  
       Sep 6, 2014
    其实。。。只是个习惯问题,写c我也喜欢缩进。。
    ijophy
        21
    ijophy  
       Sep 7, 2014
    Pycharm ……
    openroc
        22
    openroc  
       Sep 7, 2014
    vi, gg=G
    Melodic
        23
    Melodic  
       Sep 16, 2014
    vim设置了自动缩进,复制时候一般用gedit或者emacs...这个方法好像有点蠢
    chenghao
        24
    chenghao  
       Oct 14, 2014
    Pycharm
    About     Help     Advertise     Blog     API     FAQ     Solana     2946 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 74ms UTC 09:59 PVG 17:59 LAX 02:59 JFK 05:59
    Do have faith in what you're doing.
    ubao msn 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