Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87c98b2

Browse files
committed
Add various items
1 parent cae9e67 commit 87c98b2

1 file changed

Lines changed: 102 additions & 10 deletions

File tree

Doc/whatsnew/whatsnew24.tex

Lines changed: 102 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,67 @@ \section{PEP 289: Generator Expressions}
179179
implemented by Jiwon Seo with early efforts steered by Hye-Shik Chang.}
180180
\end{seealso}
181181

182+
183+
%======================================================================
184+
\section{PEP 292: Simpler String Substitutions}
185+
186+
Some new classes in the standard library provide a
187+
alternative mechanism for substituting variables into strings that's
188+
better-suited for applications where untrained users need to edit templates.
189+
190+
The usual way of substituting variables by name is the \code{\%}
191+
operator:
192+
193+
\begin{verbatim}
194+
>>> '%(page)i: %(title)s' % {'page':2, 'title': 'The Best of Times'}
195+
'2: The Best of Times'
196+
\end{verbatim}
197+
198+
When writing the template string, it can be easy to forget the
199+
\samp{i} or \samp{s} after the closing parenthesis. This isn't a big
200+
problem if the template is in a Python module, because you run the
201+
code, get an ``Unsupported format character'' \exception{ValueError},
202+
and fix the problem. However, consider an application such as Mailman
203+
where template strings or translations are being edited by users who
204+
aren't aware of the Python language; the syntax is complicated to
205+
explain to such users, and if they make a mistake, it's difficult to
206+
provide helpful feedback to them.
207+
208+
PEP 292 adds a \class{Template} class to the \module{string} module
209+
that uses \samp{\$} to indicate a substitution. \class{Template} is a
210+
subclass of the built-in Unicode type, so the result is always a
211+
Unicode string:
212+
213+
\begin{verbatim}
214+
>>> import string
215+
>>> t = string.Template('$page: $title')
216+
>>> t % {'page':2, 'title': 'The Best of Times'}
217+
u'2: The Best of Times'
218+
>>> t2 % {'cost':42.50, 'action':'polish'}
219+
u'$ 42.5: polishing'
220+
\end{verbatim}
221+
222+
% $ Terminate $-mode for Emacs
223+
224+
If a key is missing from the dictionary, the \class{Template} class
225+
will raise a \exception{KeyError}. There's also a \class{SafeTemplate}
226+
class that ignores missing keys:
227+
228+
\begin{verbatim}
229+
>>> t = string.SafeTemplate('$page: $title')
230+
>>> t % {'page':3}
231+
u'3: $title'
232+
\end{verbatim}
233+
234+
Because templates are Unicode strings, you can use a template with the
235+
\module{gettext} module to look up translated versions of a message.
236+
237+
\begin{seealso}
238+
\seepep{292}{Simpler String Substitutions}{Written and implemented
239+
by Barry Warsaw.}
240+
\end{seealso}
241+
242+
182243
%======================================================================
183244
\section{PEP 318: Decorators for Functions, Methods and Classes}
184245

@@ -306,6 +367,11 @@ \section{PEP 318: Decorators for Functions, Methods and Classes}
306367
Getting this right can be slightly brain-bending, but it's not too
307368
difficult.
308369

370+
A small related change makes the \member{func_name} attribute of
371+
functions writable. This attribute is used to display function names
372+
in tracebacks, so decorators should change the name of any new
373+
function that's constructed and returned.
374+
309375
The new syntax was provisionally added in 2.4alpha2, and is subject to
310376
change during the 2.4alpha release cycle depending on the Python
311377
community's reaction. Post-2.4 versions of Python will preserve
@@ -744,6 +810,9 @@ \section{Other Language Changes}
744810
yellow 5
745811
\end{verbatim}
746812

813+
\item Integer operations will no longer trigger an \exception{OverflowWarning}.
814+
The \exception{OverflowWarning} warning will disappear in Python 2.5.
815+
747816
\item The \function{eval(\var{expr}, \var{globals}, \var{locals})}
748817
and \function{execfile(\var{filename}, \var{globals}, \var{locals})}
749818
functions and the \keyword{exec} statement now accept any mapping type
@@ -869,7 +938,8 @@ \section{New, Improved, and Deprecated Modules}
869938
\item Korean: cp949, euc-kr, johab, iso-2022-kr
870939
\end{itemize}
871940

872-
\item Some other new encodings were added: ISO_8859-11, ISO_8859-16, PCTP-154,
941+
\item Some other new encodings were added: HP Roman8,
942+
ISO_8859-11, ISO_8859-16, PCTP-154,
873943
and TIS-620.
874944

875945
\item There is a new \module{collections} module for
@@ -1071,11 +1141,20 @@ \section{New, Improved, and Deprecated Modules}
10711141
the group didn't match, the pattern \var{B} will be used instead.
10721142

10731143
\item A new \function{socketpair()} function was added to the
1074-
\module{socket} module, returning a pair of connected sockets.
1075-
(Contributed by Dave Cole.)
1144+
\module{socket} module, returning a pair of connected sockets.
1145+
(Contributed by Dave Cole.)
10761146

10771147
% XXX sre is now non-recursive.
10781148

1149+
\item The \function{sys.exitfunc()} function has been deprecated. Code
1150+
should be using the existing \module{atexit} module, which correctly
1151+
handles calling multiple exit functions. Eventually
1152+
\function{sys.exitfunc()} will become a purely internal interface,
1153+
accessed only by \module{atexit}.
1154+
1155+
\item The \module{tarfile} module now generates GNU-format tar files
1156+
by default.
1157+
10791158
\item The \module{threading} module now has an elegantly simple way to support
10801159
thread-local data. The module contains a \class{local} class whose
10811160
attribute values are local to different threads.
@@ -1125,6 +1204,13 @@ \subsection{cookielib}
11251204
\class{HTTPCookieProcessor} manages a cookie jar that is used when
11261205
accessing URLs.
11271206

1207+
\subsection{doctest}
1208+
1209+
The \module{doctest} module underwent considerable refactoring thanks
1210+
to Edward Loper and Tim Peters.
1211+
1212+
% XXX describe this
1213+
11281214
% ======================================================================
11291215
\section{Build and C API Changes}
11301216

@@ -1158,13 +1244,16 @@ \section{Build and C API Changes}
11581244
same name. This can halve the access time for a method such as
11591245
\method{set.__contains__()}.
11601246

1161-
\item Python can now be built with additional profiling for the interpreter
1162-
itself. This is intended for people developing on the Python core.
1163-
Providing \longprogramopt{--enable-profiling} to the
1164-
\program{configure} script will let you profile the interpreter with
1165-
\program{gprof}, and providing the \longprogramopt{--with-tsc} switch
1166-
enables profiling using the Pentium's Time-Stamp-Counter register.
1167-
1247+
\item Python can now be built with additional profiling for the
1248+
interpreter itself. This is intended for people developing on the
1249+
Python core. Providing \longprogramopt{--enable-profiling} to the
1250+
\program{configure} script will let you profile the interpreter with
1251+
\program{gprof}, and providing the \longprogramopt{--with-tsc}
1252+
switch enables profiling using the Pentium's Time-Stamp-Counter
1253+
register. The switch is slightly misnamed, because the profiling
1254+
feature also works on the PowerPC platform, though that processor
1255+
architecture doesn't called that register the TSC.
1256+
11681257
\item The \ctype{tracebackobject} type has been renamed to \ctype{PyTracebackObject}.
11691258

11701259
\end{itemize}
@@ -1226,6 +1315,9 @@ \section{Porting to Python 2.4}
12261315
\item \function{fcntl.ioctl} now warns if the \var{mutate}
12271316
argument is omitted and relevant.
12281317

1318+
\item The \module{tarfile} module now generates GNU-format tar files
1319+
by default.
1320+
12291321
\end{itemize}
12301322

12311323

0 commit comments

Comments
 (0)