2006年04月28日 星期五 19:38
#!/usr/bin/python import sys import math class Aclass(object): def __init__(self,x): self.x=x def foo(self,x): return self.x*self.x-6*self.x+9 if __name__=="__main__": print Aclass.foo(100) 为什么这样的调用总是报错; TypeError: unbound method foo() must be called with Aclass instance as first argument (got int instance instead)
2006年04月28日 星期五 19:51
呵呵,这样调用,不报错才怪了。 a = Aclass() a.foo(100) 这样才是ok的。建议找Python的Tutorial再仔细看看其中的相关内容。 On 4/28/06, biosedit at gmail.com <biosedit at gmail.com> wrote: > > #!/usr/bin/python > import sys > import math > class Aclass(object): > def __init__(self,x): > self.x=x > def foo(self,x): > return self.x*self.x-6*self.x+9 > if __name__=="__main__": > print Aclass.foo(100) > 为什么这样的调用总是报错; > TypeError: unbound method foo() must be called with Aclass instance as > first argument (got int instance instead) > > _______________________________________________ > 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/20060428/f7fd23ed/attachment.html
2006年04月28日 星期五 20:12
oo概念不清;) 在 06-4-28,Robert Chen<search.pythoner at gmail.com> 写道: > > 呵呵,这样调用,不报错才怪了。 > a = Aclass() > a.foo(100) > > 这样才是ok的。建议找Python的Tutorial再仔细看看其中的相关内容。 > > > On 4/28/06, biosedit at gmail.com <biosedit at gmail.com> wrote: > > > #!/usr/bin/python > import sys > import math > class Aclass(object): > def __init__(self,x): > self.x=x > def foo(self,x): > return self.x*self.x-6*self.x+9 > if __name__=="__main__": > print Aclass.foo(100) > 为什么这样的调用总是报错; > TypeError: unbound method foo() must be called with Aclass instance as > first argument (got int instance instead) > > _______________________________________________ > 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/ > _______________________________________________ > 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 > >
2006年04月28日 星期五 21:37
#!/usr/bin/python
import sys
import math
class Aclass:
       def __init__(self,x):
           self.x=x
       def foo(self,x):
               return self.x*self.x-6*self.x+9
if __name__=="__main__":
	   a=Aclass(10)
	   print a.foo(10)
嘿嘿,
在 06-4-28,xxmplus<xxmplus at gmail.com> 写道:
> oo概念不清;)
>
> 在 06-4-28,Robert Chen<search.pythoner at gmail.com> 写道:
> >
> > 呵呵,这样调用,不报错才怪了。
> > a = Aclass()
> > a.foo(100)
> >
> > 这样才是ok的。建议找Python的Tutorial再仔细看看其中的相关内容。
> >
> >
> > On 4/28/06, biosedit at gmail.com <biosedit at gmail.com> wrote:
> > >
> > #!/usr/bin/python
> > import sys
> > import math
> > class Aclass(object):
> >        def __init__(self,x):
> >             self.x=x
> >        def foo(self,x):
> >                return self.x*self.x-6*self.x+9
> > if __name__=="__main__":
> >        print Aclass.foo(100)
> > 为什么这样的调用总是报错;
> > TypeError: unbound method foo() must be called with Aclass instance as
> > first argument (got int instance instead)
> >
> > _______________________________________________
> > 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/
> > _______________________________________________
> > 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
> >
> >
>
> _______________________________________________
> 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
>
>
Zeuux © 2025
京ICP备05028076号