2005年09月01日 星期四 13:02
俺在沈阳去不了那位大哥去能不能录下来啊, 在 05-8-31,pfuji79 at gmail.com<pfuji79 at gmail.com> 写道: > 深圳有没有这样的讲座啊? > 我也想听听哦! > > 在 05-8-31,jzx++<jzx19770812 at yahoo.com.cn> 写道: > > 嘿嘿,俺来凑个人数 > > > > On Wed, 31 Aug 2005 14:18:33 +0800 > > limodou <limodou at gmail.com> wrote: > > > > > 讲课的题纲我已经放在了wiki上,大家可以看一看,有什么意见告诉我。 > > > > > > http://wiki.woodpecker.org.cn/moin.cgi/BPUG/2005-09-04 > > > > > > -- > > > I like python! > > > My Donews Blog: http://www.donews.net/limodou > > > > -- > > jzx <jzx19770812 at yahoo.com.cn> > > > > __________________________________________________ > > Do You Yahoo!? > > 雅虎免费G邮箱-中国第一绝无垃圾邮件骚扰超大邮箱 > > http://cn.mail.yahoo.com/?id=77071 > > _______________________________________________ > > python-chinese list > > python-chinese at lists.python.cn > > http://python.cn/mailman/listinfo/python-chinese > > > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > >
2005年09月01日 星期四 13:22
1.Python的built-in函数type(object)返回值是什么类型的数据啊?比如我在PythonWin下输入: >>> x = 1 >>> type(x)>>> 那 是什么类型的数据,不是字典又不是序列,哪是什么呢?因为我想提取其中了类型信息“int”,而不需要其它的修饰?如何操作? 2.我们可以非常方便地增删Python中类对象实例的成员属性,哪有没有方法直接修改已有属性的名称呢? 谢谢! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050901/da8a601a/attachment.htm
2005年09月01日 星期四 13:25
在 05-9-1,su suyushi2004<suyushi2004 at gmail.com> 写道: > 俺在沈阳去不了那位大哥去能不能录下来啊, 这个是一定会的。 -- I like python! My Donews Blog: http://www.donews.net/limodou
2005年09月01日 星期四 13:32
在 05-9-1,xu.shengyong<zjxushengyong at hotmail.com> 写道: > > 1.Python的built-in函数type(object)返回值是什么类型的数据啊?比如我在PythonWin下输入: > > >>> x = 1 > >>> type(x) >> >>> > > 那 > 'int'>是什么类型的数据,不是字典又不是序列,哪是什么呢?因为我想提取其中了类型信息"int",而不需要其它的修饰?如何操作? 它返回的是一个类型对象。你可以到types中看到有许多的类型定义。一种方法是比较返回的类型,如: def gettype(obj): t = type(obj) import types tps = {types.IntType:'int', types.StringType:'string', types.TupleType:'tuple'} return tps.get(t, 'unknow') 这种方法需要你将想到的类型补充到tps字典中。 另外对于type()返回的值可以使用repr(type(obj))来处理,这样返回的是一个" "字符串,然后再使用re模块将单引号中的内容取出来即可。 > > 2.我们可以非常方便地增删Python中类对象实例的成员属性,哪有没有方法直接修改已有属性的名称呢? > > 谢谢! 修改的话就是先删再加了。 -- I like python! My Donews Blog: http://www.donews.net/limodou
2005年09月01日 星期四 13:32
在 05-9-1,xu.shengyong<zjxushengyong at hotmail.com> 写道: > > 1.Python的built-in函数type(object)返回值是什么类型的数据啊?比如我在PythonWin下输入: > > >>> x = 1 > >>> type(x) >> >>> > > 那 > 'int'>是什么类型的数据,不是字典又不是序列,哪是什么呢?因为我想提取其中了类型信息"int",而不需要其它的修饰?如何操作? > 就是是type型的呀,你可以用type(x).__name__ 来提取'int' > 2.我们可以非常方便地增删Python中类对象实例的成员属性,哪有没有方法直接修改已有属性的名称呢? > 这个我不知道,没有这个用过,问别人吧。谁知到说一下。
2005年09月01日 星期四 13:36
1 >>> print type(type(int))>>> 尝试正则表达式匹配? 2 一个办法提供参考: 添加一个属性,复制原来属性的内容,在删除原来的属性 __ Best Regards, Kebo Wang
2005年09月01日 星期四 14:12
谢谢 Gary Jia 和 limodou 的解答,另外,我还有一个问题,Python的built-in类型可以通过type(object)来获取变量的类型是“int”或是“str”,但是当变量是我自己定义的一个类的实例时候,获取的类信息都是“instance”,有没有方法也可以获取类的名称: >>> class CPerson: ... pass ... >>> type(CPerson)>>> var = CPerson(); >>> type(var); 有没有方法可以获取对象实例var的类型是CPerson呢?谢谢! ----- Original Message ----- From: "Gary Jia" <jiakeke at gmail.com> To: <python-chinese at lists.python.cn> Sent: Thursday, September 01, 2005 1:32 PM Subject: Re: [python-chinese] 江湖救急 :) :请教两个Python自省能力方面的小问题,谢谢! >在 05-9-1,xu.shengyong<zjxushengyong at hotmail.com> 写道: >> >> 1.Python的built-in函数type(object)返回值是什么类型的数据啊?比如我在PythonWin下输入: >> >> >>> x = 1 >> >>> type(x) >> >> >>> >> >> 那 >> 'int'>是什么类型的数据,不是字典又不是序列,哪是什么呢?因为我想提取其中了类型信息"int",而不需要其它的修饰?如何操作? >> > 就是是type型的呀,你可以用type(x).__name__ 来提取'int' > >> 2.我们可以非常方便地增删Python中类对象实例的成员属性,哪有没有方法直接修改已有属性的名称呢? >> > 这个我不知道,没有这个用过,问别人吧。谁知到说一下。 > -------------------------------------------------------------------------------- > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese >
2005年09月01日 星期四 14:12
在 05-9-1,xu.shengyong<zjxushengyong at hotmail.com> 写道: > 谢谢 Gary Jia 和 limodou 的解答,另外,我还有一个问题,Python的built-in类型可以通过type(object)来获取变量的类型是"int"或是"str",但是当变量是我自己定义的一个类的实例时候,获取的类信息都是"instance",有没有方法也可以获取类的名称: > > >>> class CPerson: > ... pass > ... > >>> type(CPerson) >> >>> var = CPerson(); > >>> type(var); > > > 有没有方法可以获取对象实例var的类型是CPerson呢?谢谢! var.__class__.__name__
2005年09月01日 星期四 14:21
多谢 Gary Jia 大虾,:),问题搞定啦,YEAH! ----- Original Message ----- From: "Gary Jia" <jiakeke at gmail.com> To: <python-chinese at lists.python.cn> Sent: Thursday, September 01, 2005 2:12 PM Subject: Re: [python-chinese] 江湖救急 :) :请教两个Python自省能力方面的小问题,谢谢! >在 05-9-1,xu.shengyong<zjxushengyong at hotmail.com> 写道: >> 谢谢 Gary Jia 和 limodou 的解答,另外,我还有一个问题,Python的built-in类型可以通过type(object)来获取变量的类型是"int"或是"str",但是当变量是我自己定义的一个类的实例时候,获取的类信息都是"instance",有没有方法也可以获取类的名称: >> >> >>> class CPerson: >> ... pass >> ... >> >>> type(CPerson) >>>> >>> var = CPerson(); >> >>> type(var); >> >> >> 有没有方法可以获取对象实例var的类型是CPerson呢?谢谢! > > var.__class__.__name__ > -------------------------------------------------------------------------------- > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese >
2005年09月01日 星期四 14:28
还有一个问题:如何获取变量自身的名称信息呢?即获取var的名称是“var” 如果我直接用 var.__name__ 会报错:“AttributeError: CPerson instance has no attribute '__name__'” >>> class CPerson: ... pass ... >>> type(CPerson)>>> var = CPerson(); >>> type(var); >>> var.__class__.__name__ 'CPerson' ----- Original Message ----- From: "Gary Jia" <jiakeke at gmail.com> To: <python-chinese at lists.python.cn> Sent: Thursday, September 01, 2005 2:12 PM Subject: Re: [python-chinese] 江湖救急 :) :请教两个Python自省能力方面的小问题,谢谢! >在 05-9-1,xu.shengyong<zjxushengyong at hotmail.com> 写道: >> 谢谢 Gary Jia 和 limodou 的解答,另外,我还有一个问题,Python的built-in类型可以通过type(object)来获取变量的类型是"int"或是"str",但是当变量是我自己定义的一个类的实例时候,获取的类信息都是"instance",有没有方法也可以获取类的名称: >> >> >>> class CPerson: >> ... pass >> ... >> >>> type(CPerson) >> >> >>> var = CPerson(); >> >>> type(var); >> >> >> 有没有方法可以获取对象实例var的类型是CPerson呢?谢谢! > > var.__class__.__name__ > -------------------------------------------------------------------------------- > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese >
2005年09月01日 星期四 14:49
如果想提供大家下载,我有个HTTP的地址是我公司的,不过小了点(100M)怕不够用需要的时候通知我。没别的意思只是想为大家也出份力
2005年09月01日 星期四 22:47
dir()的键里面应该有 for name in dir() : if eval(name) is var : print name 不过这么做有意义吗?换了个变量名对象还是对象。 真的要这么做可以做一个dict,然后用(名字,对象) 把对象储存起来,以后用。 On 9/1/05, xu.shengyong <zjxushengyong at hotmail.com> wrote: > 还有一个问题:如何获取变量自身的名称信息呢?即获取var的名称是"var" > 如果我直接用 var.__name__ 会报错:"AttributeError: CPerson instance has no attribute '__name__'" > > > >>> class CPerson: > ... pass > ... > >>> type(CPerson) >> >>> var = CPerson(); > >>> type(var); > > >>> var.__class__.__name__ > 'CPerson' > > > > ----- Original Message ----- > From: "Gary Jia" <jiakeke at gmail.com> > To: <python-chinese at lists.python.cn> > Sent: Thursday, September 01, 2005 2:12 PM > Subject: Re: [python-chinese] 江湖救急 :) :请教两个Python自省能力方面的小问题,谢谢! > > > >在 05-9-1,xu.shengyong<zjxushengyong at hotmail.com> 写道: > >> 谢谢 Gary Jia 和 limodou 的解答,另外,我还有一个问题,Python的built-in类型可以通过type(object)来获取变量的类型是"int"或是"str",但是当变量是我自己定义的一个类的实例时候,获取的类信息都是"instance",有没有方法也可以获取类的名称: > >> > >> >>> class CPerson: > >> ... pass > >> ... > >> >>> type(CPerson) > >> > >> >>> var = CPerson(); > >> >>> type(var); > >> > >> > >> 有没有方法可以获取对象实例var的类型是CPerson呢?谢谢! > > > > var.__class__.__name__ > > > > > -------------------------------------------------------------------------------- > > > > _______________________________________________ > > python-chinese list > > python-chinese at lists.python.cn > > http://python.cn/mailman/listinfo/python-chinese > > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > >
Zeuux © 2025
京ICP备05028076号