2007年03月28日 星期三 16:14
´ó¼ÒºÃ£¬ ¼ÙÉèÎÒÓÐÒ»¸ö×Ö·û´® objStr = 'context.UserManager'£¬ÎÒ¸ÃÔõô×ö²ÅÄÜͨ¹ýÕâ¸ö×Ö·û´®·ÃÎʵ½UserManagerÄØ£¿ лл -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070328/477a33a1/attachment.html
2007年03月28日 星期三 18:57
compile() On 3/28/07, Dreamer <dreamerx2004在gmail.com> wrote: > > ´ó¼ÒºÃ£¬ > > ¼ÙÉèÎÒÓÐÒ»¸ö×Ö·û´® objStr = 'context.UserManager > '£¬ÎÒ¸ÃÔõô×ö²ÅÄÜͨ¹ýÕâ¸ö×Ö·û´®·ÃÎʵ½UserManagerÄØ£¿ > > лл > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- ×¢ÒâÉíÌ壬ÉíÌåÊǸïÃüµÄ±¾Ç®£¡£¡ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070328/076dad45/attachment.html
2007年03月29日 星期四 16:46
UserManager = eval(objStr)() 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 Dreamer 发送时间: 2007年3月28日 16:15 收件人: python-chinese at lists.python.cn 主题: [python-chinese] 怎样通过字符串访问对象? 大家好, 假设我有一个字符串 objStr = 'context.UserManager',我该怎么做才能通过这 个字符串访问到UserManager呢? 谢谢 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20070329/990cd7d8/attachment.htm
2007年03月29日 星期四 17:01
Â¥Ö÷ÏëÎʵÄÊÇPythonµÄ·´Éä(reflection)ÌØÐÔ°É£¿ ÒÔÇ°¿´¹ýÒ»ÏÂÏÖÔÚ²»¼ÇµÃÁË£¬ºÃÏñ³ýÁËeval()»¹ÓÐÆäËü·½Ê½µÄ ÔÚ07-3-29£¬haoyu <haoyu在csdn.net> дµÀ£º > > UserManager = eval(objStr)() > > > > *·¢¼þÈË:* python-chinese-bounces在lists.python.cn [mailto: > python-chinese-bounces在lists.python.cn] *´ú±í *Dreamer > *·¢ËÍʱ¼ä:* 2007Äê3ÔÂ28ÈÕ 16:15 > *ÊÕ¼þÈË:* python-chinese在lists.python.cn > *Ö÷Ìâ:* [python-chinese] ÔõÑùͨ¹ý×Ö·û´®·ÃÎʶÔÏó£¿ > > > > ´ó¼ÒºÃ£¬ > > > > ¼ÙÉèÎÒÓÐÒ»¸ö×Ö·û´® objStr = 'context.UserManager'£¬ÎÒ¸ÃÔõô×ö²ÅÄÜͨ¹ýÕâ¸ö×Ö·û´®·ÃÎʵ½UserManager > ÄØ£¿ > > > > лл > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070329/7d21ace5/attachment.html
2007年03月30日 星期五 11:15
getattr(globals()['context'], 'UserManager') >>> help(getattr) Help on built-in function getattr in module __builtin__: getattr(...) getattr(object, name[, default]) -> value Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y. When a default argument is given, it is returned when the attribute doesn't exist; without it, an exception is raised in that case. >>> help(globals) Help on built-in function globals in module __builtin__: globals(...) globals() -> dictionary Return the dictionary containing the current scope's global variables. >>> help(locals) Help on built-in function locals in module __builtin__: locals(...) locals() -> dictionary Update and return a dictionary containing the current scope's local variables. >>> 在 07-3-28,Dreamer<dreamerx2004 at gmail.com> 写道: > > > 大家好, > > 假设我有一个字符串 objStr = > 'context.UserManager',我该怎么做才能通过这个字符串访问到UserManager呢? > > 谢谢 > _______________________________________________ > 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 >
Zeuux © 2025
京ICP备05028076号