我有嵌套類,因爲它們緊密相關。python如何讓內部類成爲外部類的類型
現在我想有以下類型的代碼
class one(Some-other-type):
...
// More functions here
class two(one):
// Some more functions here.
內部類「二」的類型應該是「一」,但如果我把我得到一個錯誤。 另一種方法是不讓它嵌套像下面
class one(Some-other-type):
...
// More functions here
class two(one):
// Some more functions here.
但後來我不想當模塊導入的類「兩」來訪問。 我並不真正關心「one」提供的功能,但爲了清晰的代碼,它需要在它之下。
有什麼想法?
[python中從內部類訪問外部類(的可能的複製http://stackoverflow.com/questions/2024566/access-outer-class- python) –
「但是當我導入模塊時,我不想讓類」two「可以訪問。」 Python不會打擾像'private'這樣的訪問修飾符。只需在'class _two'前加上一個下劃線來表示它是私人的。因爲在另一種情況下,總是可以通過one.two來訪問。 – Evert
@Evert是啊我猜這就是要走的路 – Anup