1, isinstance(object, classinfo)
判断object的类型是否为classinfo.
>>> a="a string"
>>> b=("1", "2")
>>> c={1:2,2:4}
>>> isinstance(a, basestring)
True
>>> isinstance(b, tuple)
True
>>> isinstance(c, dict)
True
>>>
2,dir([object])
显示object的所有属性, 当无参数时,显示当前命名空间的所有可用命名
无参数:
>>> a=1
>>> b=2
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__', 'a', 'b']
>>>
有参数 :
>>> a=1
>>> dir(a)
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delat
tr__', '__div__', '__divmod__', '__doc__', '__float__', '__floordiv__', '__forma
t__', '__getattribute__', '__getnewargs__', '__hash__', '__hex__', '__index__',
'__init__', '__int__', '__invert__', '__long__', '__lshift__', '__mod__', '__mul
__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', '__pow
__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_
ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ro
r__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rx
or__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '_
_truediv__', '__trunc__', '__xor__', 'bit_length', 'conjugate', 'denominator', '
imag', 'numerator', 'real']
>>>
3, hasattr(object, name)
判断object是否有name属性
>>> def f():
... pass
...
>>> hasattr(f,'__call__')
True
4, eval(expression[, globals[, locals]])
execfile(filename[, globals[, locals]])
将字符串expression(文件filename)作为python的code执行, 引入字典global,locals为全局和本地命名
>>> eval('3+4')
7