作者Arim (Arim5566)
看板Python
標題[問題] module跟type的問題
時間Thu May 31 01:43:22 2012
各位版友好
最近在學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)
推 ckclark:from Image import *的話 就只要寫open就好了 05/31 01:52
→ ckclark:不過這不是個好習慣就是了 namespace會被混雜 05/31 01:52
推 mikapauli:第二問題,classic class不是type,new-style class才是 05/31 03:27
→ mikapauli:要知道某instance的class可以用__class__方法 05/31 03:30
→ mikapauli:另外python3裡classic class會消失,class會和type統一 05/31 03:34