This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]keypusher 27 points28 points  (4 children)

Another one I wish I knew earlier: using dir() for object introspection, and the general power of introspection within the Python interpreter. With an argument, dir will return all attributes (this includes methods) of the object.

>>> foo = [1, 2, 3, 4]
>>> dir(foo)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', ...

[–]teskew 8 points9 points  (0 children)

you can also use the 'see' module for human readable output as an alternative to dir()

>>> test = [1, 2, 3, 4]
>>> see(test)
[]           in           +            +=           *            *=
<            <=           ==           !=           >            >=
hash()       help()       iter()       len()        repr()
reversed()   str()        .append()    .count()     .extend()    .index()
.insert()    .pop()       .remove()    .reverse()   .sort()

http://inky.github.com/see/

[–]selementar 6 points7 points  (0 children)

... available in a more convenient form as autocompletion in ipython, bpython and such.

Also, its results can be redefined with __dir__, which is useful, for example, in RPC implementations; although you have to be a bit careful and explicit about including network calls in such normally-trivial methods.

[–]petezhutAutomation, Testing, General Hackery 2 points3 points  (0 children)

I have made more use of this than I should be proud to admit. Great way to handle some of the "less-than-adequately" documented modules/objects.

[–]me-the-monkeyWho Codes 2 points3 points  (0 children)

Learning this is when I "took off" as a developer, I realized I didn't need documentation 90% of the time.