2016-05-13 39 views
2

所以有兩個問題。我在卓異文本3,其中I使用Anaconda包此塊的代碼(相關的空格將被示出爲,因爲它顯示在ST3; Python.sublime-設置在該柱的端部示出):ST3中多行字符串內Linter「行太長」錯誤和過多空白

elif choice == "taunt bear" and not bear_moved: 
••••••••print("The•bear•has•moved•from•the•door.•You•can•go•through•it•now" 
      ) 
     bear_moved = True 

第一個問題:
我已啓用Word Wrap並將標尺設置爲80,因此它會自動包裝代碼,在「print ...」和下一行有1個字符的行上有79個字符。但是linter給我一個錯誤「[W] PEP8(E501):行太長(80> 79個字符)」。我在下一行有自動縮進的右括號,因此不會違反「每行79個字符」規則。這裏可能是什麼問題?它是否應該始終少於80個字符,即使它跨越多行?

問題二:

elif choice == "taunt bear" and not bear_moved: 
••••••••print("""The•bear•has•moved•from•the•door. 
•••••••••••••••••You•can•go•through•it•now""") 
     bear_moved = True 

在這裏,我想擺脫「> 79個字符」錯誤的和做多行字符串。問題是,當我在字符串中將兩個句子分成兩行以便能夠根據PEP8規則對齊它們時,我必須將它們縮進,並且縮進意味着字符串內部有過多的空白,這不是我想要的。下面是應該第一句話結束之後理想的工作,有需要的空格字符,並沒有使用空格縮進字符串的後半部分:

elif choice == "taunt bear" and not bear_moved: 
••••••••print("""The•bear•has•moved•from•the•door.• 
       You•can•go•through•it•now""") 
     bear_moved = True 

Python.sublime設置:

{ 
    // editor options 
    "draw_white_space": "all", 

    // tabs and whitespace 
    "auto_indent": true, 
    "rulers": [80], 
    "smart_indent": true, 
    "tab_size": 4, 
    "trim_automatic_white_space": true, 
    "use_tab_stops": false, 
    "word_wrap": true, 
    "wrap_width": 80 
} 

回答

3

您可以使用Python的字符串連接機制,如示例中看到寫在單引號的字符串:

elif choice == "taunt bear" and not bear_moved: 
••••••••print("The•bear•has•moved•from•the•door.•" 
       "You•can•go•through•it•now") 
     bear_moved = True 

所以,你的代碼是PEP8兼容和STRI ng是所需的格式。