[Tutor] Optimization

Timothy M. Brauch tbrauch at mindless.com
Sat Oct 25 17:23:55 EDT 2003


From: "Daniel Ehrenberg" <littledanehren at yahoo.com>
> --- Karl Pflästerer <sigurd @ 12move.de> wrote:
> > *But*: do not use *list* as a parameter.  It is a
> > builtin.
> >    Karl
>
> Where could I find a list of builtins?

Here are a couple of places to start looking

Built-In Functions (probably what you are most concerned with):
http://www.python.org/doc/current/lib/built-in-funcs.html

All Built-in Objects (nice to be away of):
http://www.python.org/doc/current/lib/builtin.html

And the default Built-In Modules:
http://www.python.org/doc/current/modindex.html

You can also use
>>dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError',
'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError',
'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'IOError',
'ImportError', 'IndentationError', 'IndexError', 'KeyError',
'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None',
'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError',
'OverflowWarning', 'PendingDeprecationWarning', 'ReferenceError',
'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration',
'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError',
'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError',
'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError',
'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError',
'_', '__debug__', '__doc__', '__import__', '__name__', 'abs', 'apply',
'basestring', 'bool', 'buffer', 'callable', 'chr', 'classmethod', 'cmp',
'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict',
'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter',
'float', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id',
'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len',
'license', 'list', 'locals', 'long', 'map', 'max', 'min', 'object', 'oct',
'open', 'ord', 'pow', 'property', 'quit', 'range', 'raw_input', 'reduce',
'reload', 'repr', 'round', 'setattr', 'slice', 'staticmethod', 'str', 'sum',
'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip']

For those times you just want a quick list of what is built-in.  To find out
what something does, try something like
>>> print __builtins__.list.__doc__
list() -> new list
list(sequence) -> new list initialized from sequence's items
>>> print __builtins__.max.__doc__
max(sequence) -> value
max(a, b, c, ...) -> value

With a single sequence argument, return its largest item.
With two or more arguments, return the largest argument.

Just note, there are **two** underscores:
_ _ b u i l t i n s _ _
_ _ d o c _ _

dir() and __doc__ should be your friends.  And keep them in mind when
writing your own code.

 - Tim



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.530 / Virus Database: 325 - Release Date: 10/23/2003




More information about the Tutor mailing list