我就在这里
分类: Python/Ruby
2013-02-27 15:06:24
Class.forName().newInstance()的功能
tommy@ubuntu:~$ python Python 2.7.2+ (default, Oct 4 2011, 20:03:08) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from time import time >>> globals() {'__builtins__':, '__name__': '__main__', 'time': , '__doc__': None, '__package__': None} >>> globals()["time"] >>>
tommy@ubuntu:~$ python Python 2.7.2+ (default, Oct 4 2011, 20:03:08) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> globals() {'__builtins__':, '__name__': '__main__', '__doc__': None, '__package__': None} >>> globals()["time"] Traceback (most recent call last): File " ", line 1, in KeyError: 'time' >>>
tommy@ubuntu:~$ python Python 2.7.2+ (default, Oct 4 2011, 20:03:08) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> module=__import__('time') >>> module>>> se_time=getattr(module, "time") >>> se_time >>> se_time() 1332210676.294227 >>>