Re:Don't distract new programmers with OOP
by brehaut on Thursday March 17, 2011 @03:39AM
(#2335392)
In a python repl dir(object) and help, help(object) are what you are looking for. Both these functions are in the default namespace
dir(__builtins__)
Returns a list of strings for all the names bound in the prelude namespace. dir(list)
Returns a list of strings for all the methods on the list class. dir([])
Will return a all the methods on a particular instance.etc… the same caveats apply to dir with getattr etc as to method_missing. additional caveat i dont care to test; it may not work on an old style class instance.
help has its __repr__ defined to tell you how to use it. It will allow you to read the doc strings for a namespace, object or function. However i prefer to run 'pydoc -p 8888' in my projects top level; this will start an http server on port 8888 that lets you interactively browser your projects docstrings and all the modules on its pythonpath.
Hope that helps
Re:Don't distract new programmers with OOP
by knowtheory on Thursday March 17, 2011 @05:26AM
(#2335546)
Thanks :) that will be useful if i dig back into mucking around with Python.
In Ruby's REPL, i can interrogate any object for the methods it has on it (unless it's using method_missing in horrible ways), effectively allowing me to list out it's API.
As far as i'm aware, that's not the case in python's REPL, or at least, i was never able to figure out how to do it (i will fully admit to not being a python expert, but at the same time i'm not a n00b either).
Also, please note, i'm not dissing Python, i like python (just not as much as i like Ruby).
I stand by my argument about OO. It should be possible to quickly and succinctly describe what OO is supposed to do, and demonstrate how your language uses them to bundle up functionality. If you can't do that, you're doing it wrong.
Objects should not get in the way of being able to write code.
Lastly, please don't put words in my mouth. I don't think monkeypatching is relevant to the discussion, and the fact that len is not a method on objects is weird, but ultimately inconsequential.