On 31-May-10 06:19 AM, Payal wrote:
Hi,
I am trying to learn Python (again) and have some basic doubts which I
hope someone in the list can address. (English is not my first language and I
have no CS background except I can write decent shell scripts)
When I type help(something) e.g. help(list), I see many methods like,
__methodname__(). Are these something special? How do I use them and why
put "__" around them?
One more simple query. Many times I see something like this,
| D.iteritems() -> an iterator over the (key, value) items of D
What is this iterator they are talking about and how do I use these
methods because simly saying D.iteritems() does not work?
Thanks a lot in advance.
With warm regards,
-Payal
Here is an extract from the docs for Python 2.6.5.
I hope that this clarifies things.
Colin W.
2.3.2. Reserved classes of identifiers
Certain classes of identifiers (besides keywords) have special meanings.
These classes are identified by the patterns of leading and trailing
underscore characters:
_*
Not imported by from module import *. The special identifier _ is used
in the interactive interpreter to store the result of the last
evaluation; it is stored in the __builtin__ module. When not in
interactive mode, _ has no special meaning and is not defined. See
section The import statement.
Note
The name _ is often used in conjunction with internationalization; refer
to the documentation for the gettext module for more information on this
convention.
__*__
System-defined names. These names are defined by the interpreter and its
implementation (including the standard library); applications should not
expect to define additional names using this convention. The set of
names of this class defined by Python may be extended in future
versions. See section Special method names.
__*
Class-private names. Names in this category, when used within the
context of a class definition, are re-written to use a mangled form to
help avoid name clashes between “private” attributes of base and derived
classes. See section Identifiers (Names).
--
http://mail.python.org/mailman/listinfo/python-list