作者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)
1F:推 ckclark:from Image import *的话 就只要写open就好了 05/31 01:52
2F:→ ckclark:不过这不是个好习惯就是了 namespace会被混杂 05/31 01:52
3F:推 mikapauli:第二问题,classic class不是type,new-style class才是 05/31 03:27
4F:→ mikapauli:要知道某instance的class可以用__class__方法 05/31 03:30
5F:→ mikapauli:另外python3里classic class会消失,class会和type统一 05/31 03:34