You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deleting objects is safe even for deeply nested data structures.
128
-
Comparing recursive objects is now safe (doesn't dump core).
129
-
130
-
Builds on NT Alpha, and work on Win64 (NT Itanium -- sys.platform is
131
-
still 'win32') is ongoing. Supports Windows CE (confirm with Mark
132
-
Hammond)
133
-
134
-
UnboundLocalError is raised when a local variable is undefined
135
-
long, int take optional "base" parameter
136
-
137
-
string objects now have methods (though they are still immutable)
138
-
139
-
sys.version_info is a tuple: (major, minor, micro, level, serial); level
140
-
is a string "a2", "b1", "c1", or '' for a final release.
141
-
142
-
New format style '%r' inserts repr(arg) instead of str(arg).
143
-
144
-
"in" operator can now be overriden in user-defined classes to mean anything:
145
-
it calls the magic method __contains__
146
-
147
-
New calling syntax: f(*args, **kw) equivalent to apply(f, args, kw)
128
+
Various minor changes have been made to Python's syntax and built-in
129
+
functions. None of the changes are very far-reaching, but they're
130
+
handy conveniences.
131
+
132
+
A change to syntax makes it more convenient to call a given function
133
+
with a tuple of arguments and/or a dictionary of keyword arguments.
134
+
In Python 1.5 and earlier, you do this with the \builtin{apply()}
135
+
built-in function: \code{apply(f, \var{args}, \var{kw})} calls the
136
+
function \function{f()} with the argument tuple \var{args} and the
137
+
keyword arguments in the dictionary \var{kw}. Thanks to a patch from
138
+
Greg Ewing, 1.6 adds \code{f(*\var{args}, **\var{kw})} as a shorter
139
+
and clearer way to achieve the same effect. This syntax is
140
+
symmetrical with the syntax for defining functions:
141
+
142
+
\begin{verbatim}
143
+
def f(*args, **kw):
144
+
# args is a tuple of positional args,
145
+
# kw is a dictionary of keyword args
146
+
...
147
+
\end{verbatim}
148
+
149
+
A new format style is available when using the \operator{\%} operator.
150
+
'\%r' will insert the \function{repr()} of its argument. This was
151
+
also added from symmetry considerations, this time for symmetry with
152
+
the existing '\%s' format style which inserts the \function{str()} of
153
+
its argument. For example, \code{'%r %s' % ('abc', 'abc')} returns a
154
+
string containing \verb|'abc' abc|.
155
+
156
+
The \builtin{int()} and \builtin{long()} functions now accept an
157
+
optional ``base'' parameter when the first argument is a string.
158
+
\code{int('123', 10)} returns 123, while \code{int('123', 16)} returns
159
+
291. \code{int(123, 16)} raises a \exception{TypeError} exception
160
+
with the message ``can't convert non-string with explicit base''.
161
+
162
+
Previously there was no way to implement a class that overrode
163
+
Python's built-in \operator{in} operator and implemented a custom
164
+
version. \code{\var{obj} in \var{seq}} returns true if \var{obj} is
165
+
present in the sequence \var{seq}; Python computes this by simply
166
+
trying every index of the sequence until either \var{obj} is found or
167
+
an \exception{IndexError} is encountered. Moshe Zadka contributed a
168
+
patch which adds a \method{__contains__} magic method for providing a
169
+
custom implementation for \operator{in}.
170
+
171
+
Earlier versions of Python used a recursive algorithm for deleting
172
+
objects. Deeply nested data structures could cause the interpreter to
173
+
fill up the C stack and crash; Christian Tismer rewrote the deletion
174
+
logic to fix this problem. On a related note, comparing recursive
175
+
objects recursed infinitely and crashed; Jeremy Hylton rewrote the
176
+
code to no longer crash, producing a useful result instead. For
177
+
example, after this code:
178
+
179
+
\begin{verbatim}
180
+
a = []
181
+
b = []
182
+
a.append(a)
183
+
b.append(b)
184
+
\end{verbatim}
185
+
186
+
The comparison \code{a==b} returns true, because the two recursive
187
+
data structures are isomorphic.
188
+
\footnote{See the thread ``trashcan and PR\#7'' in the April 2000 archives of the python-dev mailing list for the discussion leading up to this implementation, and some useful relevant links.
0 commit comments