亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從函數調用常量時 (PEP8) 換行的正確方法是什么?

從函數調用常量時 (PEP8) 換行的正確方法是什么?

翻閱古今 2021-12-17 10:23:54
我正在使用 spyder 并且我有一個類似這樣的代碼    detector_x, detector_y, smeared_x, smeared_y = gamma_detection(decay_positions, cos_theta, phi)對于其中第二i中decay_positions超過字符的在一條線上的推薦量(像90)。我有動態 PEP8 分析,所以它自然會給我的代碼分析警告。那么在這種情況下,正確的 PEP8 方法是什么?是嗎detector_x, detector_y, smeared_x, smeared_y = \gamma_detection(decay_positions, cos_theta, phi)從技術上講,它仍在運行,但它給了我警告E122 continuation line missing indentation or outdented或者是detector_x, detector_y, smeared_x, smeared_y = gamma_detection(    decay_positions, cos_theta, phi)或者是detector_x, detector_y, smeared_x, smeared_y = gamma_detection(                                        decay_positions, cos_theta, phi)
查看完整描述

2 回答

?
溫溫醬

TA貢獻1752條經驗 獲得超4個贊

您提供了選項 {1, 2, 3}。


絕對使用 2 或 3。這是它們之間的品味問題,或者您最喜歡的編輯器鼓勵您使用的內容。(將所有內容放在一行,光標越過打開的括號,點擊 RETURN,并使用建議的縮進。)只要


$ flake8

不抱怨,你是金子。(得到它pip install flake8。)


對于大量參數或涉及冗長表達式的參數,您甚至可以考慮每行列出一個參數。


如果您要分配很多長標識符,您可以考慮在元組解包時將 LHS 括在括號中:


(detector_x, detector_y,

 smeared_x, smeared_y) = gamma_detection(

    decay_positions,

    cos_theta + epsilon * some_long_expression(),

    phi)


查看完整回答
反對 回復 2021-12-17
?
慕哥6287543

TA貢獻1831條經驗 獲得超10個贊

在 VS 代碼上使用 autopep8,您的代碼將更改為以下內容:


detector_x, detector_y, smeared_x, smeared_y = \

    gamma_detection(decay_positions, cos_theta, phi)

現在我看了一下總長度,如果這是單行的話,是 96 個字符。即使這超出了 PEP8 的約 79 個字符的限制,我仍然建議將其保留為一行。在實踐中,79 個字符非常短,如果您制作 100 個字符的行,可讀性不會降低。在我工作的地方,我們還將行長度的準則增加到 100 個字符。


# 96 characters

detector_x, detector_y, smeared_x, smeared_y = gamma_detection(decay_positions, cos_theta, phi)



查看完整回答
反對 回復 2021-12-17
  • 2 回答
  • 0 關注
  • 170 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號