Python论坛  - 讨论区

标题:[python-chinese] 为什么这样的调用总是报错

2006年04月28日 星期五 19:38

biosedit at gmail.com biosedit at gmail.com
Fri Apr 28 19:38:23 HKT 2006

#!/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)

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年04月28日 星期五 19:51

Robert Chen search.pythoner at gmail.com
Fri Apr 28 19:51:36 HKT 2006

呵呵,这样调用,不报错才怪了。
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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年04月28日 星期五 20:12

xxmplus xxmplus at gmail.com
Fri Apr 28 20:12:58 HKT 2006

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
>
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年04月28日 星期五 21:37

biosedit at gmail.com biosedit at gmail.com
Fri Apr 28 21:37:04 HKT 2006

#!/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
>
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号