Yet another newbie question - standard or built-in methods
Peter Otten
__peter__ at web.de
Fri Dec 5 07:51:14 EST 2003
Kamus of Kadizhar wrote:
> OK, I've been playing with the snippets of code posted earlier.
>
> Among them are things like
>
> allmovies[movie] = allmovies.get(movie, 0) + 1
>
> From reading the docs, I've gathered that the '.get(xxx,yyy)' part is a
> method that operates on the dictonary allmovies. (Sorry if I have the
> terminology wrong).
>
> But nowhere can I find a list of 'standard' or 'built-in' methods, or
> methods that can be used with various variable classes. What exactly
> does 'get' do? This seems to be so basic to python that it's not
> explained anywhere, but that's no help to me.... Is there a list with
> explanations somewhere? I've been through the tutorials and guides, and
> all just start using these with no explanation of what they do and how
> they work.
>
> Maybe I've missed it somewhere; just point me to the right FM, so I can
> RTFM.
>
> help is no help:
>
> help> get
> no Python documentation found for 'get'
>
> So what's a newbie to do?
Raymond Hettinger has already pointed you to the relevant part of the
documentation. I will add that help *is* helpful. You just need to provide
some context:
>>> allmovies = {}
>>> help(allmovies.get)
will show you a short explanation of the dict.get() method.
Unfortunately help({}) does not come up with the help for dictionaries, but
it does mention the class (dict), so that the next step should work to your
satisfaction:
>>> help(allmovies) # not very informative
>>> help(dict) # nice
help() has the additional benefit of working for third party (or your own)
code that provides docstrings:
>>> def foo(bar):
... "Reliably foo any bar you care to mention"
...
>>> help(foo)
Or, more likely:
>>> import otten.statistics
>>> help(otten.statistics) # and old module, hope I threw in some doc :-)
Peter
More information about the Python-list
mailing list