@@ -139,12 +139,37 @@ available. They are listed here in alphabetical order.
139
139
If no argument is given, this function returns :const: `False `.
140
140
141
141
142
+ .. function :: bytes([arg[, encoding[, errors]]])
143
+
144
+ Return a new array of bytes. The :class: `bytes ` type is a mutable sequence
145
+ of integers in the range 0 <= x < 256. It has most of the usual methods of
146
+ mutable sequences, described in :ref: `typesseq-mutable `, as well as a few
147
+ methods borrowed from strings, described in :ref: `bytes-methods `.
148
+
149
+ The optional *arg * parameter can be used to initialize the array in a few
150
+ different ways:
151
+
152
+ * If it is a *string *, you must also give the *encoding * (and optionally,
153
+ *errors *) parameters; :func: `bytes ` then acts like :meth: `str.encode `.
154
+
155
+ * If it is an *integer *, the array will have that size and will be
156
+ initialized with null bytes.
157
+
158
+ * If it is an object conforming to the *buffer * interface, a read-only buffer
159
+ of the object will be used to initialize the bytes array.
160
+
161
+ * If it is an *iterable *, it must be an iterable of integers in the range 0
162
+ <= x < 256, which are used as the initial contents of the array.
163
+
164
+ Without an argument, an array of size 0 is created.
165
+
166
+
142
167
.. function :: chr(i)
143
168
144
- Return the string of one character whose Unicode codepoint is the integer * i *. For
145
- example, ``chr(97) `` returns the string ``'a' ``. This is the inverse of
146
- :func: `ord `. The valid range for the argument depends how Python was
147
- configured -- it may be either UCS2 [0..0xFFFF] or UCS4 [0..0x10FFFF].
169
+ Return the string of one character whose Unicode codepoint is the integer
170
+ * i *. For example, ``chr(97) `` returns the string ``'a' ``. This is the
171
+ inverse of :func: `ord `. The valid range for the argument depends how Python
172
+ was configured -- it may be either UCS2 [0..0xFFFF] or UCS4 [0..0x10FFFF].
148
173
:exc: `ValueError ` will be raised if *i * is outside that range.
149
174
150
175
@@ -557,15 +582,13 @@ available. They are listed here in alphabetical order.
557
582
558
583
.. function :: isinstance(object, classinfo)
559
584
560
- Return true if the *object * argument is an instance of the *classinfo * argument,
561
- or of a (direct or indirect) subclass thereof. Also return true if *classinfo *
562
- is a type object (new-style class) and *object * is an object of that type or of
563
- a (direct or indirect) subclass thereof. If *object * is not a class instance or
564
- an object of the given type, the function always returns false. If *classinfo *
565
- is neither a class object nor a type object, it may be a tuple of class or type
566
- objects, or may recursively contain other such tuples (other sequence types are
567
- not accepted). If *classinfo * is not a class, type, or tuple of classes, types,
568
- and such tuples, a :exc: `TypeError ` exception is raised.
585
+ Return true if the *object * argument is an instance of the *classinfo *
586
+ argument, or of a (direct or indirect) subclass thereof. If *object * is not
587
+ an object of the given type, the function always returns false. If
588
+ *classinfo * is not a class (type object), it may be a tuple of type objects,
589
+ or may recursively contain other such tuples (other sequence types are not
590
+ accepted). If *classinfo * is not a type or tuple of types and such tuples,
591
+ a :exc: `TypeError ` exception is raised.
569
592
570
593
.. versionchanged :: 2.2
571
594
Support for a tuple of type information was added.
@@ -659,6 +682,13 @@ available. They are listed here in alphabetical order.
659
682
Added support for the optional *key * argument.
660
683
661
684
685
+ .. function :: memoryview(obj)
686
+
687
+ Return a "memory view" object created from the given argument.
688
+
689
+ XXX: To be documented.
690
+
691
+
662
692
.. function :: min(iterable[, args...][key])
663
693
664
694
With a single argument *iterable *, return the smallest item of a non-empty
@@ -682,9 +712,13 @@ available. They are listed here in alphabetical order.
682
712
683
713
.. function :: object()
684
714
685
- Return a new featureless object. :class: `object ` is a base for all new style
686
- classes. It has the methods that are common to all instances of new style
687
- classes.
715
+ Return a new featureless object. :class: `object ` is a base for all classes.
716
+ It has the methods that are common to all instances of Python classes.
717
+
718
+ .. note ::
719
+
720
+ :class: `object ` does *not * have a :attr: `__dict__ `, so you can't assign
721
+ arbitrary attributes to an instance of the :class: `object ` class.
688
722
689
723
.. versionadded :: 2.2
690
724
@@ -797,8 +831,7 @@ available. They are listed here in alphabetical order.
797
831
798
832
.. function :: property([fget[, fset[, fdel[, doc]]]])
799
833
800
- Return a property attribute for new-style classes (classes that derive from
801
- :class: `object `).
834
+ Return a property attribute.
802
835
803
836
*fget * is a function for getting an attribute value, likewise *fset * is a
804
837
function for setting, and *fdel * a function for del'ing, an attribute. Typical
@@ -1023,11 +1056,12 @@ available. They are listed here in alphabetical order.
1023
1056
1024
1057
.. function :: super(type[, object-or-type])
1025
1058
1059
+ .. XXX need to document PEP "new super"
1060
+
1026
1061
Return the superclass of *type *. If the second argument is omitted the super
1027
1062
object returned is unbound. If the second argument is an object,
1028
1063
``isinstance(obj, type) `` must be true. If the second argument is a type,
1029
- ``issubclass(type2, type) `` must be true. :func: `super ` only works for new-style
1030
- classes.
1064
+ ``issubclass(type2, type) `` must be true.
1031
1065
1032
1066
A typical use for calling a cooperative superclass method is::
1033
1067
@@ -1061,23 +1095,26 @@ available. They are listed here in alphabetical order.
1061
1095
1062
1096
.. index :: object: type
1063
1097
1064
- Return the type of an *object *. The return value is a type object. The
1065
- :func: `isinstance ` built-in function is recommended for testing the type of an
1066
- object.
1098
+ Return the type of an *object *. The return value is a type object and
1099
+ generally the same object as returned by ``object.__class__ ``.
1100
+
1101
+ The :func: `isinstance ` built-in function is recommended for testing the type
1102
+ of an object, because it takes subclasses into account.
1067
1103
1068
- With three arguments, :func: `type ` functions as a constructor as detailed below.
1104
+ With three arguments, :func: `type ` functions as a constructor as detailed
1105
+ below.
1069
1106
1070
1107
1071
1108
.. function :: type(name, bases, dict)
1072
1109
:noindex:
1073
1110
1074
1111
Return a new type object. This is essentially a dynamic form of the
1075
- :keyword: `class ` statement. The *name * string is the class name and becomes the
1076
- :attr: `__name__ ` attribute; the *bases * tuple itemizes the base classes and
1077
- becomes the :attr: `__bases__ ` attribute; and the *dict * dictionary is the
1078
- namespace containing definitions for class body and becomes the :attr: ` __dict__ `
1079
- attribute. For example, the following two statements create identical
1080
- :class: `type ` objects::
1112
+ :keyword: `class ` statement. The *name * string is the class name and becomes
1113
+ the :attr: `__name__ ` attribute; the *bases * tuple itemizes the base classes
1114
+ and becomes the :attr: `__bases__ ` attribute; and the *dict * dictionary is the
1115
+ namespace containing definitions for class body and becomes the
1116
+ :attr: ` __dict__ ` attribute. For example, the following two statements create
1117
+ identical :class: `type ` objects::
1081
1118
1082
1119
>>> class X(object):
1083
1120
... a = 1
@@ -1128,6 +1165,7 @@ Python programmers, trainers, students and bookwriters should feel free to
1128
1165
bypass these functions without concerns about missing something important.
1129
1166
1130
1167
1168
+ .. XXX does this go away?
1131
1169
.. function :: buffer(object[, offset[, size]])
1132
1170
1133
1171
The *object * argument must be an object that supports the buffer call interface
0 commit comments