dir – 属性を調べる



オブジェクトが持っている属性を調べるにはdirを使います。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
>>> dir(1)
['__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__', 'conjugate', 'denominator', 'imag', 'numera
tor'
, 'real']
>>> dir("egg")
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__
format__'
, '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__get
slice__'
, '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mo
d__'
, '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
 '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook
__'
, '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center',
 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index
'
, 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper',
'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', '
rjust'
, 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', '
strip'
, 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>> dir(dir)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__eq__', '__form
at__'
, '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__',
 '__lt__', '__module__', '__name__', '__ne__', '__new__', '__reduce__', '__reduc
e_ex__'
, '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subc
lasshook__'
]

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

Facebook comments:

comments

Leave a Reply


Get Adobe Flash player