看板 Python 關於我們 聯絡資訊
※ 引述《MicroPtt (Mission Start)》之銘言: : class aa(object): : def bb(self) : self.cc : 請問要怎麼把 self.cc 這行弄到外面當一個[全域變數] : 我是寫 aa.bb.cc or aa.cc : 都會說aa裡面沒有cc的 attribute : 類別學不好= = 如果觀念錯請多包含 class aa(object): cc = 'hi cc' def bb(self): self.dd = 'hi dd' global ee ee = 'hi ee' a = aa() a.bb() print a.dd print aa.cc print ee 執行後: $ ./test.py hi dd hi cc hi ee -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.129.77.13
MicroPtt:感謝 07/10 15:56