2006年03月31日 星期五 14:57
两个模块: MyTank.py //---------------------------------------------------------------------------- class Tank: "aaaaaaaaaa" def __init__(self): print 'init' def forward(self): print 'forward' //---------------------------------------------------------------------------- TankTest.py import MyTank a= MyTank() a.forward() //---------------------------------------------------------------------------- 执行TankTest.py显示如下: a=MyTank() TypeError:'module' object is not callable 请教高手该怎么修改呢? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060331/9bc400ca/attachment.html
2006年03月31日 星期五 15:02
Python中的对象有一个callable的feature,确切的说,如果对象中有"__call__"属性,那么这个对象就是callable的,就可以通过()操作符调用。 Python中的module不是callable的,这就是你的问题的根源,你需要做的改动是: a = MyTank.Tank() 因为所有的class object都是callable的 On 3/31/06, 吴俊玉 <wujunyu at gmail.com> wrote: > > 两个模块: > MyTank.py > > //---------------------------------------------------------------------------- > class Tank: > "aaaaaaaaaa" > def __init__(self): > print 'init' > > def forward(self): > print 'forward' > > //---------------------------------------------------------------------------- > TankTest.py > import MyTank > > a= MyTank() > a.forward() > > //---------------------------------------------------------------------------- > 执行TankTest.py显示如下: > a=MyTank() > TypeError:'module' object is not callable > 请教高手该怎么修改呢? > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -- Robert Python源码剖析――http://blog.donews.com/lemur/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060331/3bc25563/attachment.htm
2006年03月31日 星期五 15:08
这种形势我也尝试过,不过当时没得到正确答案, 可能当时已经晕头转向了吧 正确了,谢谢 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060331/efda3774/attachment.htm
Zeuux © 2025
京ICP备05028076号