Yet another newbie question - standard or built-in methods

  • Thread starter Kamus of Kadizhar
  • Start date
K

Kamus of Kadizhar

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?

-Kamus
 
R

Raymond Hettinger

[Kamus of Kadizhar]
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.

http://www.python.org/doc/current/lib/typesmapping.html


Raymond Hettinger
 
J

John Roth

Kamus of Kadizhar said:
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.

There are no standard methods that can be used across large
numbers of classes. The 'get' method you reference is specific
to mappings, that is, to dictionaries. Other objects that implement
a dictionary-like interface also implement it.
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.

Raymond pointed you at part of it: the full documentation set includes
a manual called the "Python Library Reference." That's the first thing
to read (well, at least skim heavily) after reading the tutorial.

John Roth
 
P

Peter Otten

Kamus said:
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:

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() has the additional benefit of working for third party (or your own)
code that provides docstrings:
.... "Reliably foo any bar you care to mention"
....
Or, more likely:

Peter
 
B

Bengt Richter

Kamus said:
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:

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() has the additional benefit of working for third party (or your own)
code that provides docstrings:
... "Reliably foo any bar you care to mention"
...
Or, more likely:
There is also the interactive help, but it seems not as useful in one way,
i.e., it does not seem to recognize dotted subjects:

Welcome to Python 2.3! This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://www.python.org/doc/tut/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics". Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help> get
no Python documentation found for 'get'

help> dict.get
no Python documentation found for 'dict.get'

help> ^Z

You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)". Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.

whereas
Help on method_descriptor:

get(...)
D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.


NB: Before you run interactive help on a totally unknown source, remember that
it is not a passive inspection of the text -- it imports, and thus executes code:
... ====< unsafe.py >====
... %s====================="""%file('unsafe.py').read()

====< unsafe.py >====
# unsafe.py
"""Show unsafe execution by interactive help through import"""
def boxit(s):
"""Return string with ascii box around it"""
width =max(map(len, s.splitlines())); bar = ['+-%s-+'%('-'*width)]
def padded(s, w=width): return s + (len(s)<w and ' '*(w-len(s)) or '' )
return '\n'.join(bar+ ['| %s |'%padded(line) for line in s.splitlines()] +bar)

print boxit('This could be\nany unsafe action!')

===================== +--------------------+
| This could be |
| any unsafe action! |
+--------------------+
Help on module unsafe:

NAME
unsafe - Show unsafe execution by interactive help through import

FILE
c:\pywk\clp\unsafe.py

FUNCTIONS
boxit(s)
Return string with ascii box around it

Also note that in the same session, repeated help will not re-execute module texts,
since import accesses previously imported modules when available.

Regards,
Bengt Richter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,172
Messages
2,570,933
Members
47,473
Latest member
ChristelPe

Latest Threads

Top