Python论坛  - 讨论区

标题:[python-chinese] 如何得到对象的名字?

2006年05月19日 星期五 21:48

flyaflya flyaflya at gmail.com
Fri May 19 21:48:09 HKT 2006

比如:
bb = 1
怎么得到bb的名字?从bb得到"bb"。

-- 
http://www.flyaflya.com powered by pygame+python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060519/1ab005a0/attachment.html

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

2006年05月20日 星期六 03:04

Leo Jay python.leojay at gmail.com
Sat May 20 03:04:25 HKT 2006

On 5/19/06, flyaflya <flyaflya at gmail.com> wrote:
>
> 比如:
> bb = 1
> 怎么得到bb的名字?从bb得到"bb"。
>
> 可是,你想由什么得到这个"bb"呢?如果是已知的变量bb中得到,那你直接写"bb"不就行了?
如果是由值来得到,那就乱了,a = 1, b = a, 那由1应该得到"a"还是"b"呢?


-- 
Best Regards,
Leo Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/c81f070e/attachment.htm

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

2006年05月20日 星期六 07:48

flyaflya flyaflya at gmail.com
Sat May 20 07:48:11 HKT 2006

这个问题我也考虑到了,唯一的方法是在locals()中查,不过可能查到多个名字。

On 5/20/06, Leo Jay <python.leojay at gmail.com> wrote:
>
> On 5/19/06, flyaflya <flyaflya at gmail.com> wrote:
> >
> > 比如:
> > bb = 1
> > 怎么得到bb的名字?从bb得到"bb"。
> >
> > 可是,你想由什么得到这个"bb"呢?如果是已知的变量bb中得到,那你直接写"bb"不就行了?
> 如果是由值来得到,那就乱了,a = 1, b = a, 那由1应该得到"a"还是"b"呢?
>
>
> --
> Best Regards,
> Leo Jay
>
> _______________________________________________
> 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
>
>


-- 
http://www.flyaflya.com powered by pygame+python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/25c58884/attachment.htm

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

2006年05月20日 星期六 10:16

ygao ygao2004 at gmail.com
Sat May 20 10:16:04 HKT 2006

这个问题有意思。就象一个人在不同的场合,有不同称呼方式一样。目前python没有这种功能。除非你要找到它的现实意义,不然实现了,也没用。



On 5/20/06, Leo Jay <python.leojay at gmail.com> wrote:
>
>  On 5/19/06, flyaflya <flyaflya at gmail.com> wrote:
> >
> > 比如:
> > bb = 1
> > 怎么得到bb的名字?从bb得到"bb"。
> >
> >  可是,你想由什么得到这个"bb"呢?如果是已知的变量bb中得到,那你直接写"bb"不就行了?
> 如果是由值来得到,那就乱了,a = 1, b = a, 那由1应该得到"a"还是"b"呢?
>
>
> --
> Best Regards,
> Leo Jay
>
> _______________________________________________
> 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
>
>


-- 
※※※※※※※※※※※※※※※※※※※※※※※※
My blog:  http://blog.donews.com/ygao
Forum    http://groups.google.com/group/python_study
※※※※※※※※※※※※※※※※※※※※※※※※
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/1f7925ac/attachment.html

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

2006年05月20日 星期六 11:35

吴俊玉 wujunyu at gmail.com
Sat May 20 11:35:33 HKT 2006

应该可以吧

flyaflya说的应该是RDDI
运行时刻类型鉴别,我记得好像是__name__
不过经测试不正确

高手指正
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/997bc32b/attachment.html

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

2006年05月20日 星期六 11:51

Ye Zhenhua yeer_mud at tom.com
Sat May 20 11:51:35 HKT 2006

Leo Jay 写道:
> On 5/19/06, *flyaflya* <flyaflya at gmail.com
> flyaflya at gmail.com>> wrote:
>
>     比如:
>     bb = 1
>     怎么得到bb的名字?从bb得到"bb"。
>
> 可是,你想由什么得到这个"bb"呢?如果是已知的变量bb中得到,那你直接写
> "bb"不就行了?
> 如果是由值来得到,那就乱了,a = 1, b = a, 那由1应该得到"a"还是"b"呢?
>
>
> -- 
> Best Regards,
> Leo Jay
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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
他应该是问如何得到一个变量的变量名吧。
例如以dict的形态返回一个对象中的所有变量,变量名是key,变量值是value


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

2006年05月20日 星期六 13:01

yi huang yi.codeplayer at gmail.com
Sat May 20 13:01:03 HKT 2006

猜测你的意思,不知对否:

def temp(arg1):
    你想在这里通过 arg1 得到 'a' ?!

a = ...
temp(a)



-- 
http://codeplayer.blogbus.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/6d16adb9/attachment.htm

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

2006年05月20日 星期六 13:04

yi huang yi.codeplayer at gmail.com
Sat May 20 13:04:11 HKT 2006

或者你只是想要个  locals()   函数?

On 5/19/06, flyaflya <flyaflya at gmail.com> wrote:
>
> 比如:
> bb = 1
> 怎么得到bb的名字?从bb得到"bb"。
>
> --
> http://www.flyaflya.com powered by pygame+python
>
> _______________________________________________
> 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
>
>


-- 
http://codeplayer.blogbus.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/cdfa29b0/attachment.html

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

2006年05月20日 星期六 13:15

flyaflya flyaflya at gmail.com
Sat May 20 13:15:42 HKT 2006

就是这个意思,只有用dict做参数了。

On 5/20/06, yi huang <yi.codeplayer at gmail.com> wrote:
>
> 猜测你的意思,不知对否:
>
> def temp(arg1):
>     你想在这里通过 arg1 得到 'a' ?!
>
> a = ...
> temp(a)
>
>
>
> --
> http://codeplayer.blogbus.com/
>
> _______________________________________________
> 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
>
>


-- 
http://www.flyaflya.com powered by pygame+python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/e67bf597/attachment.htm

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

2006年05月20日 星期六 13:20

yi huang yi.codeplayer at gmail.com
Sat May 20 13:20:06 HKT 2006

明白了,你要的不过是个 **  而已:
def test(**kw):
    print kw

test(a=1,b=2,c=3)


On 5/20/06, flyaflya <flyaflya at gmail.com> wrote:
>
> 就是这个意思,只有用dict做参数了。
>
> On 5/20/06, yi huang <yi.codeplayer at gmail.com> wrote:
>
> > 猜测你的意思,不知对否:
>
> def temp(arg1):
>     你想在这里通过 arg1 得到 'a' ?!
>
> a = ...
> temp(a)
>
>
>
> --
> http://codeplayer.blogbus.com/
>
> _______________________________________________
> 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
>
>
>
>
> --
> http://www.flyaflya.com powered by pygame+python
>
> _______________________________________________
> 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
>
>


-- 
http://codeplayer.blogbus.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060520/49d6204b/attachment.html

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号