项目作者: ljcooke

项目描述 :
Python's dir() for humans. (GitHub mirror)
高级语言: Python
项目地址: git://github.com/ljcooke/see.git
创建时间: 2009-02-16T23:36:33Z
项目社区:https://github.com/ljcooke/see

开源协议:BSD 3-Clause "New" or "Revised" License

下载


see: dir for humans

see is an alternative to dir(), for Python 2.7 and 3.4+.

It neatly summarises what you can do with an object.
Use it to inspect your code or learn new APIs.

Example

Say you have an object which you’d like to know more about:

  1. >>> from datetime import timedelta

Try inspecting the object with see:

  1. >>> see(timedelta)
  2. isclass + -
  3. * / //
  4. % +obj -obj
  5. < <= ==
  6. != > >=
  7. abs() bool() dir()
  8. divmod() hash() help()
  9. repr() str() .days
  10. .max .microseconds .min
  11. .resolution .seconds .total_seconds()

Here we can discover some things about it, such as:

  • The object is a class.
  • You can add something to it with the + operator.
  • It has a seconds attribute.
  • It has a total_seconds attribute which is a function.

Compare with the output of dir:

  1. >>> dir(timedelta)
  2. ['__abs__', '__add__', '__bool__', '__class__', '__delattr__', '
  3. __dir__', '__divmod__', '__doc__', '__eq__', '__floordiv__', '__
  4. format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '
  5. __init__', '__init_subclass__', '__le__', '__lt__', '__mod__', '
  6. __mul__', '__ne__', '__neg__', '__new__', '__pos__', '__radd__',
  7. '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rf
  8. loordiv__', '__rmod__', '__rmul__', '__rsub__', '__rtruediv__',
  9. '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclassho
  10. ok__', '__truediv__', 'days', 'max', 'microseconds', 'min', 'res
  11. olution', 'seconds', 'total_seconds']

You can filter the results of see using a wildcard pattern
or a regular expression:

  1. >>> see(timedelta).filter('*sec*')
  2. .microseconds .seconds .total_seconds()
  3. >>> see(timedelta).filter('/^d/')
  4. dir() divmod()

Documentation

Documentation is available at https://ljcooke.github.io/see.

Contributing

The source code is available from GitHub:

  1. git clone https://github.com/ljcooke/see.git

Contributions are welcome.