好的我有兩個真正大的類,每個> 1k行,每個我現在分成多個類。然後他們使用多重繼承進行重組。現在我想知道,如果有更清潔/更好的pythonic這樣做的方式。完全分解它們會導致無數次的調用,我認爲這不應該是它應該完成的方式。Python類設計 - 將大類拆分爲多個類來組合功能
爲了讓事情在這裏明確就是它現在的樣子:
from gui_events import GUIEvents # event handlers
from gui_helpers import GUIHelpers # helper methods that don't directly modify the GUI
# GUI.py
class GUI(gtk.Window, GUIEvents, GUIHelpers):
# general stuff here stuff here
的一個問題是,這是pylint的抱怨給我的萬億結果「INIT不叫」 /「未定義的屬性」 /「屬性訪問在定義之前「警告。
編輯:
你可能想看看代碼,讓自己一個什麼整件事其實是圖片。
http://github.com/BonsaiDen/Atarashii/tree/next/atarashii/usr/share/pyshared/atarashii/
請注意,我真的想什麼讓這件事儘可能乾燥,我使用pylint的檢測代碼重複,它抱怨是進口的唯一的事。
東西不加起來。問題是「>每行1k」。存儲庫中的實際代碼是356行。請修復問題或鏈接。 – 2010-03-24 10:39:35
你需要總結一下:http://github.com/BonsaiDen/Atarashii/blob/next/atarashii/usr/share/pyshared/atarashii/gui.py http://github.com/BonsaiDen/Atarashii/blob/ next/atarashii/usr/share/pyshared/atarashii/gui_events.py和http://github.com/BonsaiDen/Atarashii/blob/next/atarashii/usr/share/pyshared/atarashii/gui_helpers.py,因爲我已經將東西(目前只有968線,因爲我最近把一些東西移到其他文件)。同時檢查一起有1,1k行的視圖*文件。 – 2010-03-24 11:54:15