Python论坛  - 讨论区

标题:[python-chinese] 请教:怎么获得实例的类名?

2006年02月08日 星期三 13:21

Peng Xiaoyu peng.xiaoyu at gmail.com
Wed Feb 8 13:21:55 HKT 2006

比如,对于test能够得到所属类Test

Python 2.4.2 (#1, Nov 12 2005, 10:57:47)
[GCC 4.0.3 20051006 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Test:
...     a = 1
...
>>> test = Test()
>>> test
<__main__.Test instance at 0xb7b812ac>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060208/8963d1d1/attachment.htm

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

2006年02月08日 星期三 13:38

limodou limodou at gmail.com
Wed Feb 8 13:38:52 HKT 2006

在 06-2-8,Peng Xiaoyu<peng.xiaoyu at gmail.com> 写道:
> 比如,对于test能够得到所属类Test
>
> Python 2.4.2 (#1, Nov 12 2005, 10:57:47)
> [GCC 4.0.3 20051006 (prerelease)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> class Test:
> ...     a = 1
> ...
> >>> test = Test()
> >>> test
> <__main__.Test instance at 0xb7b812ac>
>
>
test.__class__.__name__


--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit

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

2006年02月08日 星期三 14:43

Peng Xiaoyu peng.xiaoyu at gmail.com
Wed Feb 8 14:43:30 HKT 2006

谢谢了,刚学python :)

为什么dir(Test)看不到__name__?
这一部分属于那个部分,在library reference里找了半天,难道不是属于buildin objects一类的?

在06-2-8,limodou <limodou at gmail.com> 写道:
>
> 在 06-2-8,Peng Xiaoyu<peng.xiaoyu at gmail.com> 写道:
> > 比如,对于test能够得到所属类Test
> >
> > Python 2.4.2 (#1, Nov 12 2005, 10:57:47)
> > [GCC 4.0.3 20051006 (prerelease)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> > >>> class Test:
> > ...     a = 1
> > ...
> > >>> test = Test()
> > >>> test
> > <__main__.Test instance at 0xb7b812ac>
> >
> >
> test.__class__.__name__
>
>
> --
> I like python!
> My Blog: http://www.donews.net/limodou
> NewEdit Maillist: http://groups.google.com/group/NewEdit
>
> _______________________________________________
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060208/15072ede/attachment.htm

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

2006年02月08日 星期三 14:52

limodou limodou at gmail.com
Wed Feb 8 14:52:28 HKT 2006

在 06-2-8,Peng Xiaoyu<peng.xiaoyu at gmail.com> 写道:
> 谢谢了,刚学python :)
>
> 为什么dir(Test)看不到__name__?
> 这一部分属于那个部分,在library reference里找了半天,难道不是属于buildin objects一类的?
>

有些东西是不让dir看到的。在 Python Library Reference 中的 2.3.11 Special Attributes 
有关于这部分东西的说明。

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号