2006年02月23日 星期四 12:56
就是根据一个字符串形式的类名创建这个类的实例? 根据一个字符串形式的方法名调用这个方法? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060223/c5b2917e/attachment.html
2006年02月23日 星期四 13:16
getattr(modulename,classname) On 2/23/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > > 就是根据一个字符串形式的类名创建这个类的实例? 根据一个字符串形式的方法名调用这个方法? > _______________________________________________ > 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 > > -- 李超群 mobile phone:13759961869 office phone:029-87607341 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060223/d682b6c0/attachment-0001.htm
2006年02月23日 星期四 13:17
invoke方法也一样。都是用getattr(class,attributename) On 2/23/06, 超群李 <achilles.lee at gmail.com> wrote: > > getattr(modulename,classname) > > On 2/23/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > > > > 就是根据一个字符串形式的类名创建这个类的实例? 根据一个字符串形式的方法名调用这个方法? > > _______________________________________________ > > 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 > > > > > > > -- > 李超群 > mobile phone:13759961869 > office phone:029-87607341 > -- 李超群 mobile phone:13759961869 office phone:029-87607341 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060223/5ef5b3e5/attachment.html
2006年02月23日 星期四 13:25
ok,是这样吗: my_class_def = getattr("mymodule", "MyClass") inst = my_class_def( some params for __init__ of MyClass) 然后inst就是MyClass的实例了? 在06-2-23,超群李 <achilles.lee at gmail.com> 写道: > > invoke方法也一样。都是用getattr(class,attributename) > > On 2/23/06, 超群李 <achilles.lee at gmail.com> wrote: > > > > getattr(modulename,classname) > > > > On 2/23/06, ajax chelsea < ajaxchelsea at gmail.com> wrote: > > > > > > 就是根据一个字符串形式的类名创建这个类的实例? 根据一个字符串形式的方法名调用这个方法? > > > _______________________________________________ > > > 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 > > > > > > > > > > > > -- > > 李超群 > > mobile phone:13759961869 > > office phone:029-87607341 > > > > > > -- > 李超群 > mobile phone:13759961869 > office phone:029-87607341 > > _______________________________________________ > 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/20060223/69f463ba/attachment.htm
2006年02月23日 星期四 13:30
对。 On 2/23/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > > ok,是这样吗: > > my_class_def = getattr("mymodule", "MyClass") > > inst = my_class_def( some params for __init__ of MyClass) > > 然后inst就是MyClass的实例了? > > > 在06-2-23,超群李 <achilles.lee at gmail.com> 写道: > > > > invoke方法也一样。都是用getattr(class,attributename) > > > > On 2/23/06, 超群李 <achilles.lee at gmail.com > wrote: > > > > > > getattr(modulename,classname) > > > > > > On 2/23/06, ajax chelsea < ajaxchelsea at gmail.com > wrote: > > > > > > > > 就是根据一个字符串形式的类名创建这个类的实例? 根据一个字符串形式的方法名调用这个方法? > > > > _______________________________________________ > > > > 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 > > > > > > > > > > > > > > > > > -- > > > 李超群 > > > mobile phone:13759961869 > > > office phone:029-87607341 > > > > > > > > > > > -- > > 李超群 > > mobile phone:13759961869 > > office phone:029-87607341 > > > > _______________________________________________ > > 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 > > -- 李超群 mobile phone:13759961869 office phone:029-87607341 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060223/2cb797c9/attachment.html
2006年02月23日 星期四 19:02
主意下 my_class_def = getattr(mymodule, "MyClass") mymodule 不可以用字符串表达 On 2/23/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > > ok,是这样吗: > > my_class_def = getattr("mymodule", "MyClass") > > inst = my_class_def( some params for __init__ of MyClass) > > 然后inst就是MyClass的实例了? > > > 在06-2-23,超群李 <achilles.lee at gmail.com> 写道: > > > > invoke方法也一样。都是用getattr(class,attributename) > > > > On 2/23/06, 超群李 <achilles.lee at gmail.com > wrote: > > > > > > getattr(modulename,classname) > > > > > > On 2/23/06, ajax chelsea < ajaxchelsea at gmail.com > wrote: > > > > > > > > 就是根据一个字符串形式的类名创建这个类的实例? 根据一个字符串形式的方法名调用这个方法? > > > > _______________________________________________ > > > > 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 > > > > > > > > > > > > > > > > > -- > > > 李超群 > > > mobile phone:13759961869 > > > office phone:029-87607341 > > > > > > > > > > > -- > > 李超群 > > mobile phone:13759961869 > > office phone:029-87607341 > > > > _______________________________________________ > > 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 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060223/0ca0c8eb/attachment.html
2006年02月23日 星期四 21:13
On 2/23/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > 就是根据一个字符串形式的类名创建这个类的实例? 根据一个字符串形式的方法名调用这个方法? 使用__import__可以根据一个字符串导入一个模块,而这个模块就是一个普通的模块。然后再通过名字从模块中取出真正的类。使用getattr()即可。 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit
Zeuux © 2025
京ICP备05028076号