[問題] module跟type的問題

看板Python作者 (Arim5566)時間13年前 (2012/05/31 01:43), 編輯推噓2(203)
留言5則, 2人參與, 最新討論串1/1
各位版友好 最近在學python時碰到了一些問題 from Image import * #import Image img = Image.open("test2_thumb.jpg") print type(img) 我把import Image註解掉之後,會出現: AttributeError: class Image has no attribute 'open' 但是我已經from Image import * 請問為什麼還是會出現這樣的錯誤? 第二個問題就是,我想要印出img的type print type(img) 他出現的是<type 'instance'> 但是為什麼不是出現<type 'Image'>呢? 又<type 'instance'>是什麼樣的意思? 在網路上面找了一些資料都沒辦法解答我的困惑 所以來這邊請教版友 謝謝各位版友的指教 -- ~宅男的四個徵兆~ ∠□ ○ ! * \○/ ★    (○ ? ╦╦└□ " ○□═ □   □> ║║√√ ╦══╦ ∥    |\ 一回家就上PTT 每天想正妹 以當好人為樂 忘記正妹虧欠自己 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.241.167.223 ※ 編輯: Arim 來自: 123.241.167.223 (05/31 01:43)

05/31 01:52, , 1F
from Image import *的話 就只要寫open就好了
05/31 01:52, 1F

05/31 01:52, , 2F
不過這不是個好習慣就是了 namespace會被混雜
05/31 01:52, 2F

05/31 03:27, , 3F
第二問題,classic class不是type,new-style class才是
05/31 03:27, 3F

05/31 03:30, , 4F
要知道某instance的class可以用__class__方法
05/31 03:30, 4F

05/31 03:34, , 5F
另外python3裡classic class會消失,class會和type統一
05/31 03:34, 5F
文章代碼(AID): #1FnbmzNx (Python)
文章代碼(AID): #1FnbmzNx (Python)