代码:
#encoding=utf-8
for i in dir(__builtins__):
#print "i:",i
try:
#这里的i是个字符串,并不能直接用dir(i)来生成内置方法列表,需要用eval来转换一下
if 'copy' in dir(eval(i)):
print i
except:
#当i遍历到"print"时,调用eval("print")是会报错的,随意用try来把异常捕获到然后继续执行,保证程序执行完
print "!!!! %s error occurs"%i
结果:
这里有个坑:
用i循环到"print"内置对象时,调用eval("print")会报错,导致程序直接退出