%!PS-Adobe-2.0
%%Creator: dvips(k) 5.96.1 Copyright 2007 Radical Eye Software
%%Title: paper-letter/whatsnew25.dvi
%%CreationDate: Fri Dec 19 16:19:48 2008
%%Pages: 33
%%PageOrder: Ascend
%%BoundingBox: 0 0 612 792
%%DocumentFonts: Helvetica Helvetica-Oblique Times-Roman Times-Bold
%%+ Courier Times-Italic CMSY10
%%DocumentPaperSizes: Letter
%%EndComments
%DVIPSWebPage: (www.radicaleye.com)
%DVIPSCommandLine: dvips -N0 -t letter -o paper-letter/whatsnew25.ps
%+ paper-letter/whatsnew25.dvi
%DVIPSParameters: dpi=600
%DVIPSSource: TeX output 2008.12.19:1619
%%BeginProcSet: tex.pro 0 0
%!
/TeXDict 300 dict def TeXDict begin/N{def}def/B{bind def}N/S{exch}N/X{S
N}B/A{dup}B/TR{translate}N/isls false N/vsize 11 72 mul N/hsize 8.5 72
mul N/landplus90{false}def/@rigin{isls{[0 landplus90{1 -1}{-1 1}ifelse 0
0 0]concat}if 72 Resolution div 72 VResolution div neg scale isls{
landplus90{VResolution 72 div vsize mul 0 exch}{Resolution -72 div hsize
mul 0}ifelse TR}if Resolution VResolution vsize -72 div 1 add mul TR[
matrix currentmatrix{A A round sub abs 0.00001 lt{round}if}forall round
exch round exch]setmatrix}N/@landscape{/isls true N}B/@manualfeed{
statusdict/manualfeed true put}B/@copies{/#copies X}B/FMat[1 0 0 -1 0 0]
N/FBB[0 0 0 0]N/nn 0 N/IEn 0 N/ctr 0 N/df-tail{/nn 8 dict N nn begin
/FontType 3 N/FontMatrix fntrx N/FontBBox FBB N string/base X array
/BitMaps X/BuildChar{CharBuilder}N/Encoding IEn N end A{/foo setfont}2
array copy cvx N load 0 nn put/ctr 0 N[}B/sf 0 N/df{/sf 1 N/fntrx FMat N
df-tail}B/dfs{div/sf X/fntrx[sf 0 0 sf neg 0 0]N df-tail}B/E{pop nn A
definefont setfont}B/Cw{Cd A length 5 sub get}B/Ch{Cd A length 4 sub get
}B/Cx{128 Cd A length 3 sub get sub}B/Cy{Cd A length 2 sub get 127 sub}
B/Cdx{Cd A length 1 sub get}B/Ci{Cd A type/stringtype ne{ctr get/ctr ctr
1 add N}if}B/CharBuilder{save 3 1 roll S A/base get 2 index get S
/BitMaps get S get/Cd X pop/ctr 0 N Cdx 0 Cx Cy Ch sub Cx Cw add Cy
setcachedevice Cw Ch true[1 0 0 -1 -.1 Cx sub Cy .1 sub]{Ci}imagemask
restore}B/D{/cc X A type/stringtype ne{]}if nn/base get cc ctr put nn
/BitMaps get S ctr S sf 1 ne{A A length 1 sub A 2 index S get sf div put
}if put/ctr ctr 1 add N}B/I{cc 1 add D}B/bop{userdict/bop-hook known{
bop-hook}if/SI save N @rigin 0 0 moveto/V matrix currentmatrix A 1 get A
mul exch 0 get A mul add .99 lt{/QV}{/RV}ifelse load def pop pop}N/eop{
SI restore userdict/eop-hook known{eop-hook}if showpage}N/@start{
userdict/start-hook known{start-hook}if pop/VResolution X/Resolution X
1000 div/DVImag X/IEn 256 array N 2 string 0 1 255{IEn S A 360 add 36 4
index cvrs cvn put}for pop 65781.76 div/vsize X 65781.76 div/hsize X}N
/p{show}N/RMat[1 0 0 -1 0 0]N/BDot 260 string N/Rx 0 N/Ry 0 N/V{}B/RV/v{
/Ry X/Rx X V}B statusdict begin/product where{pop false[(Display)(NeXT)
(LaserWriter 16/600)]{A length product length le{A length product exch 0
exch getinterval eq{pop true exit}if}{pop}ifelse}forall}{false}ifelse
end{{gsave TR -.1 .1 TR 1 1 scale Rx Ry false RMat{BDot}imagemask
grestore}}{{gsave TR -.1 .1 TR Rx Ry scale 1 1 false RMat{BDot}
imagemask grestore}}ifelse B/QV{gsave newpath transform round exch round
exch itransform moveto Rx 0 rlineto 0 Ry neg rlineto Rx neg 0 rlineto
fill grestore}B/a{moveto}B/delta 0 N/tail{A/delta X 0 rmoveto}B/M{S p
delta add tail}B/b{S p tail}B/c{-4 M}B/d{-3 M}B/e{-2 M}B/f{-1 M}B/g{0 M}
B/h{1 M}B/i{2 M}B/j{3 M}B/k{4 M}B/w{0 rmoveto}B/l{p -4 w}B/m{p -3 w}B/n{
p -2 w}B/o{p -1 w}B/q{p 1 w}B/r{p 2 w}B/s{p 3 w}B/t{p 4 w}B/x{0 S
rmoveto}B/y{3 2 roll p a}B/bos{/SS save N}B/eos{SS restore}B end
%%EndProcSet
%%BeginProcSet: 8r.enc 0 0
% File 8r.enc TeX Base 1 Encoding Revision 2.0 2002-10-30
%
% @@psencodingfile@{
% author = "S. Rahtz, P. MacKay, Alan Jeffrey, B. Horn, K. Berry,
% W. Schmidt, P. Lehman",
% version = "2.0",
% date = "27nov06",
% filename = "8r.enc",
% email = "tex-fonts@@tug.org",
% docstring = "This is the encoding vector for Type1 and TrueType
% fonts to be used with TeX. This file is part of the
% PSNFSS bundle, version 9"
% @}
%
% The idea is to have all the characters normally included in Type 1 fonts
% available for typesetting. This is effectively the characters in Adobe
% Standard encoding, ISO Latin 1, Windows ANSI including the euro symbol,
% MacRoman, and some extra characters from Lucida.
%
% Character code assignments were made as follows:
%
% (1) the Windows ANSI characters are almost all in their Windows ANSI
% positions, because some Windows users cannot easily reencode the
% fonts, and it makes no difference on other systems. The only Windows
% ANSI characters not available are those that make no sense for
% typesetting -- rubout (127 decimal), nobreakspace (160), softhyphen
% (173). quotesingle and grave are moved just because it's such an
% irritation not having them in TeX positions.
%
% (2) Remaining characters are assigned arbitrarily to the lower part
% of the range, avoiding 0, 10 and 13 in case we meet dumb software.
%
% (3) Y&Y Lucida Bright includes some extra text characters; in the
% hopes that other PostScript fonts, perhaps created for public
% consumption, will include them, they are included starting at 0x12.
% These are /dotlessj /ff /ffi /ffl.
%
% (4) hyphen appears twice for compatibility with both ASCII and Windows.
%
% (5) /Euro was assigned to 128, as in Windows ANSI
%
% (6) Missing characters from MacRoman encoding incorporated as follows:
%
% PostScript MacRoman TeXBase1
% -------------- -------------- --------------
% /notequal 173 0x16
% /infinity 176 0x17
% /lessequal 178 0x18
% /greaterequal 179 0x19
% /partialdiff 182 0x1A
% /summation 183 0x1B
% /product 184 0x1C
% /pi 185 0x1D
% /integral 186 0x81
% /Omega 189 0x8D
% /radical 195 0x8E
% /approxequal 197 0x8F
% /Delta 198 0x9D
% /lozenge 215 0x9E
%
/TeXBase1Encoding [
% 0x00
/.notdef /dotaccent /fi /fl
/fraction /hungarumlaut /Lslash /lslash
/ogonek /ring /.notdef /breve
/minus /.notdef /Zcaron /zcaron
% 0x10
/caron /dotlessi /dotlessj /ff
/ffi /ffl /notequal /infinity
/lessequal /greaterequal /partialdiff /summation
/product /pi /grave /quotesingle
% 0x20
/space /exclam /quotedbl /numbersign
/dollar /percent /ampersand /quoteright
/parenleft /parenright /asterisk /plus
/comma /hyphen /period /slash
% 0x30
/zero /one /two /three
/four /five /six /seven
/eight /nine /colon /semicolon
/less /equal /greater /question
% 0x40
/at /A /B /C
/D /E /F /G
/H /I /J /K
/L /M /N /O
% 0x50
/P /Q /R /S
/T /U /V /W
/X /Y /Z /bracketleft
/backslash /bracketright /asciicircum /underscore
% 0x60
/quoteleft /a /b /c
/d /e /f /g
/h /i /j /k
/l /m /n /o
% 0x70
/p /q /r /s
/t /u /v /w
/x /y /z /braceleft
/bar /braceright /asciitilde /.notdef
% 0x80
/Euro /integral /quotesinglbase /florin
/quotedblbase /ellipsis /dagger /daggerdbl
/circumflex /perthousand /Scaron /guilsinglleft
/OE /Omega /radical /approxequal
% 0x90
/.notdef /.notdef /.notdef /quotedblleft
/quotedblright /bullet /endash /emdash
/tilde /trademark /scaron /guilsinglright
/oe /Delta /lozenge /Ydieresis
% 0xA0
/.notdef /exclamdown /cent /sterling
/currency /yen /brokenbar /section
/dieresis /copyright /ordfeminine /guillemotleft
/logicalnot /hyphen /registered /macron
% 0xB0
/degree /plusminus /twosuperior /threesuperior
/acute /mu /paragraph /periodcentered
/cedilla /onesuperior /ordmasculine /guillemotright
/onequarter /onehalf /threequarters /questiondown
% 0xC0
/Agrave /Aacute /Acircumflex /Atilde
/Adieresis /Aring /AE /Ccedilla
/Egrave /Eacute /Ecircumflex /Edieresis
/Igrave /Iacute /Icircumflex /Idieresis
% 0xD0
/Eth /Ntilde /Ograve /Oacute
/Ocircumflex /Otilde /Odieresis /multiply
/Oslash /Ugrave /Uacute /Ucircumflex
/Udieresis /Yacute /Thorn /germandbls
% 0xE0
/agrave /aacute /acircumflex /atilde
/adieresis /aring /ae /ccedilla
/egrave /eacute /ecircumflex /edieresis
/igrave /iacute /icircumflex /idieresis
% 0xF0
/eth /ntilde /ograve /oacute
/ocircumflex /otilde /odieresis /divide
/oslash /ugrave /uacute /ucircumflex
/udieresis /yacute /thorn /ydieresis
] def
%%EndProcSet
%%BeginProcSet: texps.pro 0 0
%!
TeXDict begin/rf{findfont dup length 1 add dict begin{1 index/FID ne 2
index/UniqueID ne and{def}{pop pop}ifelse}forall[1 index 0 6 -1 roll
exec 0 exch 5 -1 roll VResolution Resolution div mul neg 0 0]FontType 0
ne{/Metrics exch def dict begin Encoding{exch dup type/integertype ne{
pop pop 1 sub dup 0 le{pop}{[}ifelse}{FontMatrix 0 get div Metrics 0 get
div def}ifelse}forall Metrics/Metrics currentdict end def}{{1 index type
/nametype eq{exit}if exch pop}loop}ifelse[2 index currentdict end
definefont 3 -1 roll makefont/setfont cvx]cvx def}def/ObliqueSlant{dup
sin S cos div neg}B/SlantFont{4 index mul add}def/ExtendFont{3 -1 roll
mul exch}def/ReEncodeFont{CharStrings rcheck{/Encoding false def dup[
exch{dup CharStrings exch known not{pop/.notdef/Encoding true def}if}
forall Encoding{]exch pop}{cleartomark}ifelse}if/Encoding exch def}def
end
%%EndProcSet
%%BeginFont: CMSY10
%!PS-AdobeFont-1.1: CMSY10 1.0
%%CreationDate: 1991 Aug 15 07:20:57
% Copyright (C) 1997 American Mathematical Society. All Rights Reserved.
11 dict begin
/FontInfo 7 dict dup begin
/version (1.0) readonly def
/Notice (Copyright (C) 1997 American Mathematical Society. All Rights Reserved) readonly def
/FullName (CMSY10) readonly def
/FamilyName (Computer Modern) readonly def
/Weight (Medium) readonly def
/ItalicAngle -14.035 def
/isFixedPitch false def
end readonly def
/FontName /CMSY10 def
/PaintType 0 def
/FontType 1 def
/FontMatrix [0.001 0 0 0.001 0 0] readonly def
/Encoding 256 array
0 1 255 {1 index exch /.notdef put} for
dup 15 /bullet put
readonly def
/FontBBox{-29 -960 1116 775}readonly def
currentdict end
currentfile eexec
D9D66F633B846A97B686A97E45A3D0AA052F09F9C8ADE9D907C058B87E9B6964
7D53359E51216774A4EAA1E2B58EC3176BD1184A633B951372B4198D4E8C5EF4
A213ACB58AA0A658908035BF2ED8531779838A960DFE2B27EA49C37156989C85
E21B3ABF72E39A89232CD9F4237FC80C9E64E8425AA3BEF7DED60B122A52922A
221A37D9A807DD01161779DDE7D31FF2B87F97C73D63EECDDA4C49501773468A
27D1663E0B62F461F6E40A5D6676D1D12B51E641C1D4E8E2771864FC104F8CBF
5B78EC1D88228725F1C453A678F58A7E1B7BD7CA700717D288EB8DA1F57C4F09
0ABF1D42C5DDD0C384C7E22F8F8047BE1D4C1CC8E33368FB1AC82B4E96146730
DE3302B2E6B819CB6AE455B1AF3187FFE8071AA57EF8A6616B9CB7941D44EC7A
71A7BB3DF755178D7D2E4BB69859EFA4BBC30BD6BB1531133FD4D9438FF99F09
4ECC068A324D75B5F696B8688EEB2F17E5ED34CCD6D047A4E3806D000C199D7C
515DB70A8D4F6146FE068DC1E5DE8BC5703711DA090312BA3FC00A08C453C609
C627A8BECD6E1FA14A3B02476E90AAD8B4700C400380BC9AFFBF7847EB28661B
9DC3AA0F44C533F2E07DCC4DE19D367BF223E33DC321D0247A0E6EF6ABC8FA52
15AE044094EF678A8726CD7C011F02BFF8AB6EAEEE391AD837120823BED0B5D8
F8B15245377871A64F78378BB4330149D6941F7A86FBFFC49B93C94155F5FA7D
F22E7214511C0A92693F4CDBF38411651540572F2DD70D924AE0F18E1CD581F3
C871399127FF5D07A868885B5FF7CDEB50B8323B2533DEF8DC973B1AE84FA0A2
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
cleartomark
%%EndFont
TeXDict begin 40258431 52099146 1000 600 600
(paper-letter/whatsnew25.dvi) @start /Fa 162[40 1[40
91[{TeXBase1Encoding ReEncodeFont}2 119.552 /Times-Roman
rf /Fb 167[48 9[48 4[22 73[{TeXBase1Encoding ReEncodeFont}3
66.4176 /Times-Roman rf /Fc 133[50 50 50 72 50 55 28
50 33 55 55 55 55 83 22 50 1[22 55 55 28 55 55 50 55
55 9[94 2[61 66 2[66 78 1[83 3[28 3[66 1[72 10[55 2[55
55 55 55 55 2[28 33 42[50 2[{TeXBase1Encoding ReEncodeFont}43
99.6264 /Helvetica rf /Fd 240[42 15[{}1 83.022 /CMSY10
rf /Fe 133[42 42 42 60 42 46 23 42 28 46 46 46 46 69
18 42 1[18 46 46 1[46 46 42 46 46 9[78 1[60 51 55 60
1[55 65 60 69 46 2[23 1[65 51 55 1[60 55 55 6[23 46 46
46 46 46 46 46 46 46 46 1[23 28 23 4[18 36[42 2[{
TeXBase1Encoding ReEncodeFont}57 83.022 /Helvetica rf
/Ff 107[46 46 24[32 37 37 55 37 42 23 32 32 42 42 42
42 60 23 37 23 23 42 42 23 37 42 37 42 42 9[69 51 60
46 42 51 1[51 60 1[69 46 55 1[28 1[60 51 51 60 55 51
51 6[28 7[42 42 42 23 21 28 41[42 42 2[{TeXBase1Encoding ReEncodeFont}
56 83.022 /Times-Italic rf /Fg 130[45 45 45 45 45 45
45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45
45 45 45 45 45 45 45 1[45 45 45 1[45 45 45 45 45 45 45
45 1[45 45 45 45 45 45 1[45 45 45 45 45 45 45 45 45 45
45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45
45 45 45 45 45 45 45 45 45 1[45 45 45 33[{TeXBase1Encoding ReEncodeFont}
88 74.7198 /Courier rf /Fh 131[50 1[50 50 50 50 50 50
50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50
50 50 1[50 1[50 50 50 50 50 50 50 50 50 50 50 50 50 50
50 50 50 50 50 1[50 50 50 50 50 50 50 50 50 1[50 1[50
1[50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50
50 50 50 50 1[50 1[50 50 34[{TeXBase1Encoding ReEncodeFont}82
83.022 /Courier rf /Fi 133[37 42 42 60 42 46 28 32 37
1[46 42 46 69 23 46 1[23 46 42 28 37 46 37 46 42 9[83
1[60 55 46 60 1[51 65 60 78 55 2[32 1[65 51 55 1[60 55
60 1[42 4[28 42 42 42 42 42 42 42 42 42 42 23 21 28 21
4[28 36[46 2[{TeXBase1Encoding ReEncodeFont}59 83.022
/Times-Bold rf /Fj 103[25 29[37 37 37 54 37 42 21 37
25 42 42 42 42 62 17 37 17 17 42 42 21 42 42 37 42 42
9[71 2[46 50 2[50 58 54 62 1[50 1[21 1[58 46 50 1[54
2[76 5[21 1[42 42 42 42 42 42 42 42 42 21 21 25 45[{
TeXBase1Encoding ReEncodeFont}54 74.7198 /Helvetica rf
/Fk 75[28 11[28 17[42 1[37 37 24[37 42 42 60 42 42 23
32 28 42 42 42 42 65 23 42 23 23 42 42 28 37 42 37 42
37 28 5[51 60 60 78 60 60 51 46 55 60 46 60 60 74 51
60 32 28 60 60 46 51 60 55 55 60 1[37 1[47 1[23 23 42
42 42 42 42 42 42 42 42 42 23 21 28 21 47 42 28 28 28
1[69 1[42 4[28 26[46 46 2[{TeXBase1Encoding ReEncodeFont}86
83.022 /Times-Roman rf /Fl 133[60 60 60 86 60 66 33 60
40 1[66 66 66 100 27 60 1[27 66 66 33 66 66 60 66 66
11[86 73 80 86 1[80 93 86 100 66 80 1[33 1[93 73 80 1[86
80 80 6[33 66 66 66 66 66 66 66 66 66 66 33 33 40 33
4[27 36[60 2[{TeXBase1Encoding ReEncodeFont}58 119.552
/Helvetica rf /Fm 140[50 6[22 6[55 3[55 14[72 32[55 55
1[28 46[{TeXBase1Encoding ReEncodeFont}8 99.6264 /Helvetica-Oblique
rf /Fn 134[103 1[149 2[57 103 3[115 115 4[46 115 2[115
3[115 9[195 6[138 1[149 24[115 2[115 3[57 6[46 39[{
TeXBase1Encoding ReEncodeFont}17 206.559 /Helvetica rf
end
%%EndProlog
%%BeginSetup
%%Feature: *Resolution 600dpi
TeXDict begin
%%BeginPaperSize: Letter
/setpagedevice where
{ pop << /PageSize [612 792] >> setpagedevice }
{ /letter where { pop letter } if }
ifelse
%%EndPaperSize
end
%%EndSetup
%%Page: 1 1
TeXDict begin 1 0 bop 0 83 3901 9 v 1550 354 a Fn(What')-10
b(s)57 b(Ne)l(w)g(in)g(Python)h(2.5)3313 525 y Fm(Release)29
b(1.01)3166 880 y Fl(A.M.)k(K)l(uchling)3248 1234 y Fk(December)18
b(19,)i(2008)3442 1381 y Fj(
[email protected])0 1661 y Fl(Contents)0
1847 y Fi(1)83 b(PEP)20 b(308:)k(Conditional)c(Expr)o(essions)2514
b(2)0 2029 y(2)83 b(PEP)20 b(309:)k(P)o(artial)19 b(Function)h(A)n
(pplication)2361 b(3)0 2212 y(3)83 b(PEP)20 b(314:)k(Metadata)19
b(f)n(or)h(Python)f(Softwar)o(e)g(P)o(ackages)g(v1.1)1785
b(5)0 2395 y(4)83 b(PEP)20 b(328:)k(Absolute)c(and)h(Relati)o(v)o(e)f
(Imports)2293 b(5)0 2577 y(5)83 b(PEP)20 b(338:)k(Executing)c(Modules)h
(as)g(Scripts)2333 b(6)0 2760 y(6)83 b(PEP)20 b(341:)k(Uni\002ed)d
(try/except/\002nally)2497 b(7)0 2943 y(7)83 b(PEP)20
b(342:)k(New)d(Generator)d(F)n(eatur)o(es)2504 b(7)0
3125 y(8)83 b(PEP)20 b(343:)k(The)d('with')f(statement)2598
b(10)125 3225 y Fk(8.1)85 b(Writing)21 b(Conte)o(xt)e(Managers)60
b(.)41 b(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)
h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g
(.)g(.)h(.)f(.)g(.)g(.)102 b(11)125 3324 y(8.2)85 b(The)20
b(conte)o(xtlib)f(module)74 b(.)41 b(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)
g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h
(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102
b(13)0 3507 y Fi(9)83 b(PEP)20 b(352:)k(Exceptions)c(as)h(New-Style)e
(Classes)2196 b(14)0 3690 y(10)41 b(PEP)20 b(353:)k(Using)d(ssize)p
870 3690 25 4 v 30 w(t)f(as)h(the)f(index)h(type)2280
b(14)0 3872 y(11)41 b(PEP)20 b(357:)k(The)d(')p 672 3872
V 702 3872 V 60 w(index)p 926 3872 V 955 3872 V 59 w(')g(method)2520
b(15)0 4055 y(12)41 b(Other)19 b(Language)h(Changes)2783
b(16)125 4155 y Fk(12.1)43 b(Interacti)n(v)o(e)19 b(Interpreter)f
(Changes)45 b(.)c(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g
(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)
g(.)g(.)h(.)f(.)g(.)g(.)102 b(18)125 4254 y(12.2)43 b(Optimizations)g
(.)e(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)
f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g
(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102 b(18)0
4437 y Fi(13)41 b(New)-5 b(,)20 b(Impr)o(o)o(v)o(ed,)g(and)h(Remo)o(v)o
(ed)f(Modules)2300 b(19)125 4537 y Fk(13.1)43 b(The)20
b(ctypes)g(package)45 b(.)c(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g
(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)
f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102
b(25)125 4636 y(13.2)43 b(The)20 b(ElementT)m(ree)f(package)80
b(.)41 b(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)
h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g
(.)g(.)h(.)f(.)g(.)g(.)102 b(26)125 4736 y(13.3)43 b(The)20
b(hashlib)g(package)79 b(.)42 b(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g
(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)
f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102
b(28)125 4835 y(13.4)43 b(The)20 b(sqlite3)h(package)35
b(.)41 b(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f
(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102 b(29)125 4935
y(13.5)43 b(The)20 b(wsgiref)g(package)70 b(.)42 b(.)f(.)g(.)g(.)h(.)f
(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)
h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g
(.)g(.)102 b(30)0 5118 y Fi(14)41 b(Build)21 b(and)g(C)f(API)h(Changes)
2774 b(31)125 5217 y Fk(14.1)43 b(Port-Speci\002c)20
b(Changes)i(.)42 b(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f
(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)
h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102 b(33)0
5400 y Fi(15)41 b(P)n(orting)19 b(to)h(Python)g(2.5)2936
b(33)p eop end
%%Page: 2 2
TeXDict begin 2 1 bop 0 83 a Fi(16)41 b(Ackno)o(wledgements)3005
b(33)p 0 230 3901 9 v 0 476 a Fk(This)26 b(article)g(e)o(xplains)e(the)
i(ne)n(w)g(features)f(in)h(Python)e(2.5.)41 b(The)26
b(\002nal)g(release)f(of)h(Python)f(2.5)g(is)h(scheduled)f(for)g
(August)g(2006;)0 576 y(PEP)c(356)e(describes)h(the)g(planned)f
(release)h(schedule.)0 723 y(The)k(changes)g(in)h(Python)e(2.5)h(are)g
(an)h(interesting)f(mix)g(of)g(language)f(and)h(library)g(impro)o(v)o
(ements.)35 b(The)24 b(library)g(enhancements)0 823 y(will)19
b(be)e(more)g(important)g(to)h(Python')-5 b(s)17 b(user)h(community)-5
b(,)15 b(I)j(think,)g(because)f(se)n(v)o(eral)g(widely-useful)f
(packages)h(were)g(added.)23 b(Ne)n(w)0 922 y(modules)18
b(include)h(ElementT)m(ree)f(for)h(XML)g(processing)f(\(section)h
(13.2\),)f(the)i(SQLite)g(database)f(module)f(\(section)h(13.4\),)f
(and)h(the)0 1022 y Fh(ctypes)h Fk(module)e(for)i(calling)g(C)h
(functions)e(\(section)g(13.1\).)0 1169 y(The)i(language)f(changes)g
(are)i(of)f(middling)f(signi\002cance.)28 b(Some)21 b(pleasant)g(ne)n
(w)g(features)g(were)g(added,)g(b)n(ut)g(most)h(of)f(them)g(aren')o(t)0
1268 y(features)j(that)g(you')o(ll)f(use)h(e)n(v)o(ery)f(day)-5
b(.)36 b(Conditional)23 b(e)o(xpressions)g(were)h(\002nally)g(added)f
(to)h(the)h(language)d(using)i(a)g(no)o(v)o(el)f(syntax;)0
1368 y(see)c(section)f(1.)24 b(The)18 b(ne)n(w)h(')p
Fh(with)p Fk(')e(statement)h(will)h(mak)o(e)f(writing)g(cleanup)f(code)
h(easier)g(\(section)g(8\).)24 b(V)-9 b(alues)18 b(can)h(no)n(w)e(be)i
(passed)0 1468 y(into)25 b(generators)f(\(section)h(7\).)41
b(Imports)25 b(are)g(no)n(w)g(visible)h(as)g(either)f(absolute)g(or)g
(relati)n(v)o(e)g(\(section)g(4\).)41 b(Some)25 b(corner)g(cases)h(of)0
1567 y(e)o(xception)20 b(handling)g(are)i(handled)f(better)h(\(section)
f(6\).)30 b(All)23 b(these)g(impro)o(v)o(ements)c(are)j(w)o(orthwhile,)
f(b)n(ut)h(the)o(y')l(re)e(impro)o(v)o(ements)0 1667
y(to)g(one)g(speci\002c)g(language)f(feature)g(or)h(another;)f(none)g
(of)h(them)g(are)g(broad)f(modi\002cations)f(to)j(Python')-5
b(s)19 b(semantics.)0 1814 y(As)g(well)g(as)f(the)g(language)f(and)g
(library)g(additions,)h(other)f(impro)o(v)o(ements)e(and)j(b)n(ug\002x)
o(es)f(were)h(made)f(throughout)e(the)j(source)g(tree.)0
1913 y(A)23 b(search)g(through)d(the)j(SVN)g(change)e(logs)i(\002nds)g
(there)f(were)h(353)e(patches)i(applied)e(and)h(458)g(b)n(ugs)h(\002x)o
(ed)f(between)g(Python)f(2.4)0 2013 y(and)f(2.5.)k(\(Both)c(\002gures)g
(are)g(lik)o(ely)g(to)g(be)g(underestimates.\))0 2160
y(This)41 b(article)f(doesn')o(t)f(try)h(to)h(be)g(a)f(complete)g
(speci\002cation)g(of)g(the)g(ne)n(w)h(features;)50 b(instead)40
b(changes)f(are)i(brie\003y)f(intro-)0 2259 y(duced)32
b(using)g(helpful)f(e)o(xamples.)62 b(F)o(or)32 b(full)h(details,)j
(you)c(should)g(al)o(w)o(ays)h(refer)f(to)h(the)f(documentation)e(for)i
(Python)g(2.5)g(at)0 2359 y Fj(
http://docs)o(.p)n(ython.org)-6
b Fk(.)32 b(If)23 b(you)e(w)o(ant)h(to)h(understand)d(the)j(complete)e
(implementation)f(and)i(design)g(rationale,)f(refer)h(to)h(the)f(PEP)0
2459 y(for)e(a)g(particular)f(ne)n(w)h(feature.)0 2606
y(Comments,)h(suggestions,)g(and)g(error)f(reports)h(for)g(this)h
(document)e(are)h(welcome;)h(please)f(e-mail)h(them)f(to)g(the)h
(author)e(or)i(open)e(a)0 2705 y(b)n(ug)g(in)g(the)g(Python)f(b)n(ug)h
(track)o(er)-5 b(.)0 3033 y Fl(1)120 b(PEP)32 b(308:)43
b(Conditional)35 b(Expressions)0 3265 y Fk(F)o(or)19
b(a)g(long)f(time,)h(people)f(ha)n(v)o(e)h(been)f(requesting)f(a)j(w)o
(ay)f(to)g(write)g(conditional)e(e)o(xpressions,)h(which)g(are)h(e)o
(xpressions)f(that)h(return)0 3365 y(v)n(alue)j(A)i(or)f(v)n(alue)f(B)i
(depending)d(on)h(whether)g(a)i(Boolean)e(v)n(alue)h(is)h(true)f(or)f
(f)o(alse.)34 b(A)24 b(conditional)d(e)o(xpression)h(lets)i(you)e
(write)h(a)0 3465 y(single)d(assignment)f(statement)h(that)h(has)f(the)
g(same)h(ef)n(fect)e(as)i(the)f(follo)n(wing:)236 3703
y Fg(if)45 b(condition:)416 3794 y(x)f(=)h(true_value)236
3885 y(else:)416 3977 y(x)f(=)h(false_value)0 4263 y
Fk(There)24 b(ha)n(v)o(e)g(been)g(endless)h(tedious)f(discussions)h(of)
f(syntax)g(on)g(both)g(p)o(ython-de)n(v)e(and)i(comp.lang.p)o(ython.)34
b(A)25 b(v)n(ote)g(w)o(as)h(e)n(v)o(en)0 4363 y(held)j(that)g(found)f
(the)i(majority)e(of)h(v)n(oters)g(w)o(anted)g(conditional)f(e)o
(xpressions)g(in)h(some)h(form,)g(b)n(ut)g(there)e(w)o(as)j(no)e
(syntax)f(that)0 4463 y(w)o(as)d(preferred)d(by)h(a)i(clear)f(majority)
-5 b(.)35 b(Candidates)24 b(included)e(C')-5 b(s)26 b
Fh(cond)49 b(?)99 b(true_v)49 b(:)99 b(false_v)p Fk(,)24
b Fh(if)50 b(cond)f(then)0 4562 y(true_v)g(else)g(false_v)p
Fk(,)19 b(and)h(16)f(other)h(v)n(ariations.)0 4709 y(Guido)f(v)n(an)h
(Rossum)g(e)n(v)o(entually)f(chose)g(a)i(surprising)e(syntax:)236
4856 y Fg(x)45 b(=)g(true_value)e(if)h(condition)g(else)g(false_value)0
5143 y Fk(Ev)n(aluation)16 b(is)j(still)h(lazy)e(as)h(in)f(e)o(xisting)
f(Boolean)h(e)o(xpressions,)f(so)h(the)g(order)f(of)h(e)n(v)n(aluation)
f(jumps)g(around)f(a)j(bit.)25 b(The)17 b Ff(condition)0
5242 y Fk(e)o(xpression)23 b(in)h(the)h(middle)e(is)j(e)n(v)n(aluated)d
(\002rst,)j(and)e(the)g Ff(true)p 1856 5242 25 4 v 30
w(value)f Fk(e)o(xpression)g(is)j(e)n(v)n(aluated)d(only)g(if)i(the)f
(condition)f(w)o(as)i(true.)0 5342 y(Similarly)-5 b(,)19
b(the)h Ff(false)p 629 5342 V 30 w(value)g Fk(e)o(xpression)e(is)j
(only)f(e)n(v)n(aluated)f(when)g(the)h(condition)f(is)i(f)o(alse.)p
0 5549 3901 4 v 0 5649 a Fe(2)2455 b(1)83 b(PEP)24 b(308:)30
b(Conditional)25 b(Expressions)p eop end
%%Page: 3 3
TeXDict begin 3 2 bop 0 83 a Fk(This)27 b(syntax)g(may)f(seem)h
(strange)g(and)f(backw)o(ards;)j(why)d(does)h(the)g(condition)e(go)i
(in)g(the)g Ff(middle)g Fk(of)g(the)g(e)o(xpression,)f(and)h(not)0
183 y(in)d(the)g(front)e(as)j(in)e(C')-5 b(s)25 b Fh(c)50
b(?)99 b(x)50 b(:)99 b(y)p Fk(?)36 b(The)24 b(decision)f(w)o(as)h
(check)o(ed)e(by)i(applying)d(the)j(ne)n(w)g(syntax)f(to)g(the)h
(modules)f(in)h(the)0 282 y(standard)g(library)f(and)h(seeing)h(ho)n(w)
f(the)g(resulting)g(code)g(read.)38 b(In)24 b(man)o(y)g(cases)h(where)f
(a)h(conditional)e(e)o(xpression)g(is)j(used,)f(one)0
382 y(v)n(alue)e(seems)i(to)f(be)g(the)g('common)d(case')j(and)g(one)f
(v)n(alue)g(is)i(an)f('e)o(xceptional)e(case',)i(used)g(only)f(on)h
(rarer)f(occasions)g(when)h(the)0 482 y(condition)18
b(isn')o(t)i(met.)25 b(The)20 b(conditional)f(syntax)g(mak)o(es)h(this)
h(pattern)e(a)i(bit)f(more)g(ob)o(vious:)236 720 y Fg(contents)44
b(=)g(\(\(doc)g(+)h('\\n'\))f(if)h(doc)f(else)g(''\))0
1006 y Fk(I)26 b(read)g(the)g(abo)o(v)o(e)f(statement)h(as)h(meaning)e
(\223here)g Ff(contents)h Fk(is)h(usually)f(assigned)f(a)i(v)n(alue)f
(of)g Fh(doc+'\\n')p Fk(;)i(sometimes)e Ff(doc)g Fk(is)0
1106 y(empty)-5 b(,)20 b(in)h(which)f(special)h(case)g(an)g(empty)f
(string)g(is)i(returned.)-6 b(\224)25 b(I)d(doubt)d(I)i(will)h(use)f
(conditional)e(e)o(xpressions)g(v)o(ery)h(often)g(where)0
1206 y(there)g(isn')o(t)g(a)g(clear)g(common)f(and)g(uncommon)f(case.)0
1353 y(There)23 b(w)o(as)i(some)e(discussion)h(of)f(whether)g(the)h
(language)e(should)h(require)g(surrounding)d(conditional)i(e)o
(xpressions)h(with)h(paren-)0 1452 y(theses.)h(The)20
b(decision)g(w)o(as)h(made)e(to)i Ff(not)e Fk(require)g(parentheses)g
(in)i(the)f(Python)f(language')-5 b(s)19 b(grammar)m(,)e(b)n(ut)k(as)f
(a)h(matter)f(of)g(style)g(I)0 1552 y(think)f(you)h(should)f(al)o(w)o
(ays)i(use)f(them.)25 b(Consider)19 b(these)h(tw)o(o)h(statements:)236
1790 y Fg(#)45 b(First)f(version)g(--)g(no)h(parens)236
1881 y(level)f(=)h(1)g(if)f(logging)g(else)g(0)236 2064
y(#)h(Second)f(version)f(--)i(with)f(parens)236 2155
y(level)g(=)h(\(1)f(if)h(logging)f(else)g(0\))0 2442
y Fk(In)18 b(the)f(\002rst)i(v)o(ersion,)e(I)h(think)f(a)h(reader')-5
b(s)17 b(e)o(ye)g(might)g(group)g(the)g(statement)h(into)f(')o(le)n(v)o
(el)h(=)g(1',)g('if)f(logging',)f('else)i(0',)g(and)f(think)g(that)0
2541 y(the)24 b(condition)d(decides)i(whether)g(the)g(assignment)g(to)h
Ff(le)o(vel)f Fk(is)i(performed.)32 b(The)23 b(second)g(v)o(ersion)f
(reads)h(better)m(,)h(in)f(my)h(opinion,)0 2641 y(because)c(it)g(mak)o
(es)g(it)h(clear)f(that)h(the)f(assignment)f(is)i(al)o(w)o(ays)g
(performed)d(and)h(the)h(choice)g(is)h(being)e(made)h(between)f(tw)o(o)
i(v)n(alues.)0 2788 y(Another)16 b(reason)g(for)h(including)e(the)i
(brack)o(ets:)23 b(a)18 b(fe)n(w)f(odd)f(combinations)f(of)i(list)h
(comprehensions)c(and)j(lambdas)f(could)g(look)g(lik)o(e)0
2888 y(incorrect)23 b(conditional)g(e)o(xpressions.)36
b(See)25 b(PEP)g(308)f(for)f(some)i(e)o(xamples.)36 b(If)25
b(you)e(put)h(parentheses)g(around)e(your)h(conditional)0
2987 y(e)o(xpressions,)c(you)g(w)o(on')o(t)g(run)g(into)h(this)h(case.)
0 3134 y Fi(See)g(Also:)0 3281 y Fk(PEP)g(308,)e(\223)p
Ff(Conditional)f(Expr)m(essions)p Fk(\224)208 3381 y(PEP)i(written)g
(by)g(Guido)f(v)n(an)h(Rossum)g(and)g(Raymond)f(D.)h(Hettinger;)f
(implemented)g(by)g(Thomas)h(W)-7 b(outers.)0 3708 y
Fl(2)120 b(PEP)32 b(309:)43 b(P)-5 b(ar)5 b(tial)33 b(Function)i
(Application)0 3941 y Fk(The)20 b Fh(functools)f Fk(module)g(is)i
(intended)e(to)h(contain)f(tools)h(for)g(functional-style)e
(programming.)0 4088 y(One)k(useful)f(tool)h(in)g(this)h(module)d(is)j
(the)f Fh(partial\(\))f Fk(function.)28 b(F)o(or)22 b(programs)e
(written)i(in)g(a)g(functional)f(style,)h(you')o(ll)f(some-)0
4187 y(times)k(w)o(ant)g(to)h(construct)d(v)n(ariants)i(of)f(e)o
(xisting)h(functions)e(that)i(ha)n(v)o(e)f(some)h(of)g(the)g
(parameters)f(\002lled)h(in.)39 b(Consider)24 b(a)i(Python)0
4287 y(function)e Fh(f\(a,)49 b(b,)h(c\))p Fk(;)29 b(you)c(could)f
(create)i(a)g(ne)n(w)g(function)e Fh(g\(b,)49 b(c\))26
b Fk(that)g(w)o(as)h(equi)n(v)n(alent)d(to)i Fh(f\(1,)49
b(b,)g(c\))p Fk(.)43 b(This)26 b(is)0 4387 y(called)20
b(\223partial)g(function)e(application\224.)0 4533 y
Fh(partial)i Fk(tak)o(es)h(the)g(ar)o(guments)e Fh(\()p
Ff(function)p Fh(,)47 b Ff(ar)m(g1)p Fh(,)i Ff(ar)m(g2)p
Fh(,)f(...)99 b Ff(kwar)m(g1)p Fh(=)p Ff(value1)p Fh(,)47
b Ff(kwar)m(g2)p Fh(=)p Ff(value2)p Fh(\))p Fk(.)24 b(The)c(resulting)0
4633 y(object)g(is)h(callable,)e(so)i(you)e(can)h(just)h(call)g(it)g
(to)f(in)m(v)n(ok)o(e)f Ff(function)g Fk(with)h(the)g(\002lled-in)g(ar)
o(guments.)0 4780 y(Here')-5 b(s)20 b(a)h(small)g(b)n(ut)f(realistic)h
(e)o(xample:)p 0 5549 3901 4 v 3854 5649 a Fe(3)p eop
end
%%Page: 4 4
TeXDict begin 4 3 bop 236 174 a Fg(import)44 b(functools)236
357 y(def)h(log)f(\(message,)f(subsystem\):)416 448 y("Write)g(the)i
(contents)e(of)i('message')e(to)h(the)h(specified)e(subsystem.")416
540 y(print)h('\045s:)g(\045s')g(\045)h(\(subsystem,)e(message\))416
631 y(...)236 814 y(server_log)g(=)i(functools.partial\(log,)c
(subsystem='server'\))236 905 y(server_log\('Unable)h(to)j(open)f
(socket'\))0 1191 y Fk(Here')-5 b(s)19 b(another)e(e)o(xample,)h(from)f
(a)i(program)e(that)i(uses)g(PyGTK.)f(Here)h(a)g(conte)o(xt-sensiti)n
(v)o(e)e(pop-up)f(menu)i(is)i(being)d(constructed)0 1291
y(dynamically)-5 b(.)23 b(The)c(callback)g(pro)o(vided)f(for)h(the)h
(menu)f(option)g(is)i(a)g(partially)e(applied)g(v)o(ersion)g(of)h(the)g
Fh(open_item\(\))e Fk(method,)0 1391 y(where)i(the)g(\002rst)h(ar)o
(gument)d(has)i(been)f(pro)o(vided.)236 1629 y Fg(...)236
1720 y(class)44 b(Application:)416 1812 y(def)g(open_item\(self,)e
(path\):)550 1903 y(...)416 1994 y(def)i(init)g(\(self\):)595
2086 y(open_func)f(=)i(functools.partial\(self.open_item,)39
b(item_path\))595 2177 y(popup_menu.append\()j(\("Open",)h(open_func,)g
(1\))i(\))0 2464 y Fk(Another)24 b(function)f(in)j(the)f
Fh(functools)f Fk(module)g(is)i(the)g Fh(update_wrapper\()p
Ff(wr)o(apper)r Fh(,)46 b Ff(wr)o(apped)r Fh(\))24 b
Fk(function)f(that)j(helps)0 2563 y(you)i(write)h(well-beha)n(v)o(ed)d
(decorators.)49 b Fh(update_wrapper\(\))27 b Fk(copies)h(the)h(name,)h
(module,)f(and)g(docstring)e(attrib)n(ute)h(to)h(a)0
2663 y(wrapper)d(function)f(so)i(that)h(tracebacks)e(inside)g(the)i
(wrapped)d(function)g(are)i(easier)h(to)f(understand.)43
b(F)o(or)27 b(e)o(xample,)g(you)f(might)0 2762 y(write:)236
3001 y Fg(def)45 b(my_decorator\(f\):)416 3092 y(def)f(wrapper\()955
3105 y(*)1000 3092 y(args,)1267 3105 y(**)1357 3092 y(kwds\):)595
3183 y(print)g('Calling)f(decorated)h(function')595 3275
y(return)g(f\()999 3288 y(*)1044 3275 y(args,)1312 3288
y(**)1402 3275 y(kwds\))416 3366 y(functools.update_wrapper\(wrapper,)
39 b(f\))416 3457 y(return)k(wrapper)0 3744 y Fh(wraps\(\))19
b Fk(is)j(a)e(decorator)f(that)h(can)g(be)g(used)g(inside)g(your)f(o)n
(wn)h(decorators)e(to)j(cop)o(y)e(the)h(wrapped)f(function')-5
b(s)19 b(information.)k(An)0 3843 y(alternate)d(v)o(ersion)f(of)g(the)i
(pre)n(vious)d(e)o(xample)h(w)o(ould)h(be:)236 4082 y
Fg(def)45 b(my_decorator\(f\):)416 4173 y(@functools.wraps\(f\))416
4264 y(def)f(wrapper\()955 4277 y(*)1000 4264 y(args,)1267
4277 y(**)1357 4264 y(kwds\):)595 4356 y(print)g('Calling)f(decorated)h
(function')595 4447 y(return)g(f\()999 4460 y(*)1044
4447 y(args,)1312 4460 y(**)1402 4447 y(kwds\))416 4538
y(return)f(wrapper)0 4825 y Fi(See)21 b(Also:)0 4972
y Fk(PEP)g(309,)e(\223)p Ff(P)-7 b(artial)20 b(Function)f(Application)p
Fk(\224)208 5072 y(PEP)d(proposed)d(and)i(written)h(by)f(Peter)h
(Harris;)h(implemented)d(by)h(Hye-Shik)f(Chang)h(and)g(Nick)h(Coghlan,)
f(with)h(adaptations)208 5171 y(by)j(Raymond)g(Hettinger)-5
b(.)p 0 5549 3901 4 v 0 5649 a Fe(4)2340 b(2)83 b(PEP)24
b(309:)29 b(P)m(ar)s(tial)24 b(Function)g(Application)p
eop end
%%Page: 5 5
TeXDict begin 5 4 bop 0 88 a Fl(3)120 b(PEP)32 b(314:)43
b(Metadata)36 b(f)l(or)e(Python)g(Softw)n(are)i(P)-5
b(ac)n(kages)34 b(v1.1)0 321 y Fk(Some)21 b(simple)f(dependenc)o(y)e
(support)i(w)o(as)i(added)d(to)i(Distutils.)28 b(The)21
b Fh(setup\(\))f Fk(function)f(no)n(w)i(has)g Fh(requires)p
Fk(,)f Fh(provides)p Fk(,)0 421 y(and)g Fh(obsoletes)g
Fk(k)o(e)o(yw)o(ord)f(parameters.)25 b(When)c(you)f(b)n(uild)g(a)h
(source)g(distrib)n(ution)e(using)h(the)h Fh(sdist)g
Fk(command,)d(the)j(depen-)0 520 y(denc)o(y)e(information)f(will)i(be)h
(recorded)d(in)i(the)g(`)p Fj(PKG-INFO)p Fk(')g(\002le.)0
667 y(Another)i(ne)n(w)i(k)o(e)o(yw)o(ord)e(parameter)g(is)j
Fh(download_url)p Fk(,)e(which)g(should)g(be)h(set)h(to)f(a)g(URL)h
(for)e(the)h(package')-5 b(s)22 b(source)h(code.)0 767
y(This)d(means)g(it')-5 b(s)21 b(no)n(w)f(possible)f(to)i(look)e(up)h
(an)g(entry)f(in)h(the)g(package)f(inde)o(x,)f(determine)h(the)h
(dependencies)e(for)h(a)i(package,)d(and)0 866 y(do)n(wnload)g(the)i
(required)f(packages.)236 1013 y Fg(VERSION)44 b(=)h('1.0')236
1104 y(setup\(name='PyPackage',)505 1196 y(version=VERSION,)505
1287 y(requires=['numarray',)d('zlib)i(\(>=1.1.4\)'],)505
1378 y(obsoletes=['OldPackage'])505 1470 y
(download_url=\('
http://www.example.com/py)o(packag)o(e/dist)o
(/pkg-\045)o(s.tar.)o(gz')1133 1561 y(\045)h(VERSION\),)460
1652 y(\))0 1939 y Fk(Another)23 b(ne)n(w)g(enhancement)f(to)i(the)g
(Python)f(package)f(inde)o(x)h(at)i Fj(
http://cheeseshop)m(.p)n
(ython.o)o(rg)18 b Fk(is)25 b(storing)e(source)g(and)h(binary)0
2039 y(archi)n(v)o(es)19 b(for)h(a)g(package.)k(The)c(ne)n(w)g
Fh(upload)f Fk(Distutils)i(command)e(will)i(upload)d(a)j(package)e(to)h
(the)g(repository)-5 b(.)0 2185 y(Before)17 b(a)i(package)d(can)i(be)f
(uploaded,)f(you)h(must)h(be)g(able)g(to)g(b)n(uild)f(a)i(distrib)n
(ution)d(using)h(the)h Fh(sdist)g Fk(Distutils)h(command.)j(Once)0
2285 y(that)d(w)o(orks,)f(you)g(can)g(run)g Fh(python)49
b(setup.py)f(upload)18 b Fk(to)h(add)f(your)f(package)h(to)g(the)h
(PyPI)g(archi)n(v)o(e.)k(Optionally)17 b(you)h(can)0
2385 y(GPG-sign)i(the)g(package)f(by)h(supplying)e(the)i
Fi(--sign)g Fk(and)g Fi(--identity)f Fk(options.)0 2532
y(P)o(ackage)g(uploading)f(w)o(as)j(implemented)d(by)i(Martin)g(v)n(on)
f(L)7 b(\250)-35 b(owis)21 b(and)e(Richard)h(Jones.)0
2678 y Fi(See)h(Also:)0 2825 y Fk(PEP)g(314,)e(\223)p
Ff(Metadata)g(for)h(Python)f(Softwar)m(e)h(P)-7 b(ac)n(ka)o(g)o(es)20
b(v1.1)p Fk(\224)208 2925 y(PEP)k(proposed)e(and)i(written)g(by)f(A.M.)
h(K)o(uchling,)g(Richard)f(Jones,)i(and)f(Fred)f(Drak)o(e;)j
(implemented)c(by)i(Richard)g(Jones)208 3025 y(and)19
b(Fred)h(Drak)o(e.)0 3352 y Fl(4)120 b(PEP)32 b(328:)43
b(Absolute)35 b(and)f(Relativ)m(e)g(Impor)5 b(ts)0 3585
y Fk(The)25 b(simpler)f(part)h(of)g(PEP)h(328)e(w)o(as)i(implemented)d
(in)i(Python)f(2.4:)34 b(parentheses)24 b(could)h(no)n(w)f(be)h(used)g
(to)g(enclose)g(the)g(names)0 3684 y(imported)18 b(from)i(a)g(module)f
(using)g(the)i Fh(from)49 b(...)99 b(import)48 b(...)25
b Fk(statement,)20 b(making)f(it)i(easier)f(to)g(import)f(man)o(y)g
(dif)n(ferent)0 3784 y(names.)0 3931 y(The)h(more)g(complicated)f(part)
h(has)g(been)g(implemented)f(in)h(Python)g(2.5:)25 b(importing)18
b(a)j(module)e(can)h(be)h(speci\002ed)f(to)h(use)f(absolute)0
4031 y(or)27 b(package-relati)n(v)o(e)d(imports.)45 b(The)27
b(plan)g(is)h(to)f(mo)o(v)o(e)f(to)n(w)o(ard)h(making)e(absolute)i
(imports)f(the)i(def)o(ault)e(in)i(future)e(v)o(ersions)g(of)0
4130 y(Python.)0 4277 y(Let')-5 b(s)21 b(say)f(you)g(ha)n(v)o(e)f(a)i
(package)d(directory)h(lik)o(e)h(this:)236 4515 y Fg(pkg/)236
4607 y(pkg/__init__.py)236 4698 y(pkg/main.py)236 4789
y(pkg/string.py)0 5076 y Fk(This)g(de\002nes)g(a)h(package)e(named)g
Fh(pkg)h Fk(containing)e(the)i Fh(pkg.main)g Fk(and)f
Fh(pkg.string)g Fk(submodules.)0 5223 y(Consider)h(the)h(code)f(in)g
(the)h(`)p Fj(main.p)n(y)p Fk(')e(module.)25 b(What)c(happens)e(if)i
(it)g(e)o(x)o(ecutes)f(the)g(statement)h Fh(import)49
b(string)p Fk(?)25 b(In)c(Python)0 5322 y(2.4)16 b(and)g(earlier)m(,)h
(it)g(will)g(\002rst)h(look)e(in)h(the)f(package')-5
b(s)16 b(directory)f(to)i(perform)d(a)j(relati)n(v)o(e)f(import,)g
(\002nds)h(`)p Fj(pkg/str)q(ing.p)n(y)p Fk(',)e(imports)h(the)p
0 5549 3901 4 v 3854 5649 a Fe(5)p eop end
%%Page: 6 6
TeXDict begin 6 5 bop 0 83 a Fk(contents)18 b(of)g(that)h(\002le)g(as)g
(the)g Fh(pkg.string)e Fk(module,)g(and)i(that)f(module)f(is)j(bound)d
(to)h(the)h(name)f(`)p Fh(string)p Fk(')f(in)i(the)f
Fh(pkg.main)0 183 y Fk(module')-5 b(s)19 b(namespace.)0
330 y(That')-5 b(s)29 b(\002ne)g(if)g Fh(pkg.string)f
Fk(w)o(as)h(what)g(you)f(w)o(anted.)50 b(But)30 b(what)f(if)g(you)f(w)o
(anted)g(Python')-5 b(s)28 b(standard)g Fh(string)g Fk(module?)0
429 y(There')-5 b(s)27 b(no)g(clean)g(w)o(ay)g(to)h(ignore)e
Fh(pkg.string)g Fk(and)h(look)f(for)h(the)h(standard)e(module;)j
(generally)d(you)h(had)g(to)g(look)g(at)h(the)0 529 y(contents)j(of)g
Fh(sys.modules)p Fk(,)i(which)e(is)i(slightly)f(unclean.)58
b(Holger)31 b(Krek)o(el')-5 b(s)31 b Fh(py.std)h Fk(package)e(pro)o
(vides)g(a)i(tidier)g(w)o(ay)0 628 y(to)24 b(perform)e(imports)h(from)g
(the)h(standard)f(library)-5 b(,)23 b Fh(import)49 b(py)g(;)h
(py.std.string.join\(\))p Fk(,)21 b(b)n(ut)j(that)g(package)f(isn')o(t)
0 728 y(a)n(v)n(ailable)d(on)g(all)g(Python)f(installations.)0
875 y(Reading)d(code)f(which)h(relies)h(on)f(relati)n(v)o(e)g(imports)g
(is)h(also)g(less)g(clear)m(,)g(because)f(a)g(reader)g(may)g(be)g
(confused)f(about)g(which)h(module,)0 975 y Fh(string)21
b Fk(or)h Fh(pkg.string)p Fk(,)e(is)j(intended)d(to)i(be)g(used.)29
b(Python)21 b(users)g(soon)h(learned)e(not)i(to)f(duplicate)g(the)h
(names)f(of)h(standard)0 1074 y(library)h(modules)g(in)h(the)g(names)g
(of)f(their)h(packages')e(submodules,)h(b)n(ut)h(you)f(can')o(t)g
(protect)g(against)h(ha)n(ving)f(your)f(submodule')-5
b(s)0 1174 y(name)20 b(being)f(used)h(for)f(a)i(ne)n(w)f(module)f
(added)g(in)h(a)h(future)e(v)o(ersion)g(of)h(Python.)0
1321 y(In)31 b(Python)g(2.5,)j(you)c(can)i(switch)g Fh(import)p
Fk(')-5 b(s)31 b(beha)n(viour)f(to)i(absolute)f(imports)g(using)g(a)h
Fh(from)49 b(__future__)f(import)0 1420 y(absolute_import)17
b Fk(directi)n(v)o(e.)23 b(This)c(absolute-import)d(beha)n(viour)g
(will)k(become)d(the)i(def)o(ault)f(in)h(a)g(future)f(v)o(ersion)f
(\(probably)0 1520 y(Python)h(2.7\).)23 b(Once)18 b(absolute)g(imports)
g(are)h(the)g(def)o(ault,)f Fh(import)49 b(string)18
b Fk(will)h(al)o(w)o(ays)g(\002nd)g(the)g(standard)e(library')-5
b(s)18 b(v)o(ersion.)0 1620 y(It')-5 b(s)25 b(suggested)d(that)i(users)
h(should)d(be)o(gin)h(using)g(absolute)h(imports)f(as)h(much)f(as)i
(possible,)f(so)g(it')-5 b(s)25 b(preferable)d(to)i(be)o(gin)f(writing)
0 1719 y Fh(from)49 b(pkg)g(import)g(string)20 b Fk(in)g(your)f(code.)0
1866 y(Relati)n(v)o(e)36 b(imports)f(are)g(still)i(possible)f(by)f
(adding)g(a)h(leading)f(period)f(to)i(the)g(module)e(name)h(when)g
(using)h(the)f Fh(from)50 b(...)0 1966 y(import)20 b
Fk(form:)236 2204 y Fg(#)45 b(Import)f(names)g(from)g(pkg.string)236
2295 y(from)g(.string)g(import)g(name1,)g(name2)236 2386
y(#)h(Import)f(pkg.string)236 2478 y(from)g(.)h(import)f(string)0
2764 y Fk(This)18 b(imports)g(the)g Fh(string)g Fk(module)f(relati)n(v)
o(e)g(to)i(the)f(current)f(package,)g(so)i(in)f Fh(pkg.main)g
Fk(this)g(will)h(import)f Ff(name1)f Fk(and)h Ff(name2)0
2864 y Fk(from)25 b Fh(pkg.string)p Fk(.)41 b(Additional)25
b(leading)g(periods)g(perform)e(the)j(relati)n(v)o(e)g(import)f
(starting)g(from)g(the)h(parent)f(of)h(the)g(current)0
2964 y(package.)d(F)o(or)d(e)o(xample,)f(code)g(in)i(the)f
Fh(A.B.C)g Fk(module)f(can)h(do:)236 3202 y Fg(from)44
b(.)h(import)f(D)762 b(#)45 b(Imports)e(A.B.D)236 3293
y(from)h(..)h(import)f(E)717 b(#)45 b(Imports)e(A.E)236
3384 y(from)h(..F)h(import)f(G)672 b(#)45 b(Imports)e(A.F.G)0
3671 y Fk(Leading)29 b(periods)h(cannot)g(be)g(used)h(with)f(the)h
Fh(import)49 b Ff(modname)29 b Fk(form)g(of)i(the)f(import)g
(statement,)j(only)d(the)g Fh(from)50 b(...)0 3771 y(import)20
b Fk(form.)0 3918 y Fi(See)h(Also:)0 4065 y Fk(PEP)g(328,)e(\223)p
Ff(Imports:)24 b(Multi-Line)c(and)g(Absolute/Relative)p
Fk(\224)208 4164 y(PEP)g(written)g(by)g(Aahz;)g(implemented)e(by)i
(Thomas)f(W)-7 b(outers.)0 4311 y Fj(
http://codespeak.net/p)n(y/curre)o
(nt/)o(doc/i)o(nd)o(e)n(x.h)o(tml)208 4411 y Fk(The)19
b(p)o(y)h(library)f(by)h(Holger)g(Krek)o(el,)f(which)h(contains)f(the)h
Fh(py.std)g Fk(package.)0 4738 y Fl(5)120 b(PEP)32 b(338:)43
b(Ex)l(ecuting)35 b(Modules)f(as)f(Scr)r(ipts)0 4971
y Fk(The)28 b Fi(-m)h Fk(switch)g(added)f(in)h(Python)e(2.4)h(to)h(e)o
(x)o(ecute)e(a)i(module)f(as)h(a)g(script)g(gained)e(a)i(fe)n(w)g(more)
e(abilities.)51 b(Instead)28 b(of)h(being)0 5070 y(implemented)15
b(in)i(C)g(code)f(inside)h(the)g(Python)e(interpreter)m(,)g(the)i
(switch)g(no)n(w)f(uses)i(an)e(implementation)f(in)i(a)g(ne)n(w)f
(module,)g Fh(runpy)p Fk(.)0 5217 y(The)23 b Fh(runpy)g
Fk(module)g(implements)f(a)i(more)f(sophisticated)g(import)f(mechanism)
h(so)h(that)f(it')-5 b(s)25 b(no)n(w)e(possible)g(to)h(run)f(modules)f
(in)0 5317 y(a)28 b(package)d(such)i(as)h Fh(pychecker.checker)p
Fk(.)43 b(The)27 b(module)f(also)h(supports)g(alternati)n(v)o(e)e
(import)i(mechanisms)f(such)h(as)h(the)p 0 5549 3901
4 v 0 5649 a Fe(6)2258 b(5)83 b(PEP)24 b(338:)29 b(Ex)n(ecuting)23
b(Modules)h(as)f(Scr)q(ipts)p eop end
%%Page: 7 7
TeXDict begin 7 6 bop 0 83 a Fh(zipimport)26 b Fk(module.)45
b(This)27 b(means)g(you)g(can)g(add)f(a)i(.zip)f(archi)n(v)o(e')-5
b(s)26 b(path)h(to)h Fh(sys.path)e Fk(and)h(then)f(use)i(the)f
Fi(-m)h Fk(switch)f(to)0 183 y(e)o(x)o(ecute)19 b(code)g(from)g(the)i
(archi)n(v)o(e.)0 330 y Fi(See)g(Also:)0 476 y Fk(PEP)g(338,)e(\223)p
Ff(Executing)f(modules)i(as)g(scripts)p Fk(\224)208 576
y(PEP)g(written)g(and)g(implemented)e(by)i(Nick)g(Coghlan.)0
903 y Fl(6)120 b(PEP)32 b(341:)43 b(Uni\002ed)35 b(tr)t(y/e)l
(xcept/\002nally)0 1136 y Fk(Until)26 b(Python)e(2.5,)i(the)f
Fh(try)g Fk(statement)g(came)h(in)f(tw)o(o)h(\003a)n(v)n(ours.)40
b(Y)-9 b(ou)25 b(could)f(use)i(a)f Fh(finally)g Fk(block)f(to)i(ensure)
f(that)g(code)g(is)0 1236 y(al)o(w)o(ays)f(e)o(x)o(ecuted,)f(or)h(one)f
(or)g(more)g Fh(except)h Fk(blocks)f(to)h(catch)g(speci\002c)g(e)o
(xceptions.)34 b(Y)-9 b(ou)23 b(couldn')o(t)f(combine)g(both)h
Fh(except)0 1336 y Fk(blocks)18 b(and)h(a)g Fh(finally)f
Fk(block,)g(because)h(generating)e(the)i(right)f(bytecode)f(for)i(the)g
(combined)e(v)o(ersion)g(w)o(as)j(complicated)d(and)i(it)0
1435 y(w)o(asn')o(t)h(clear)g(what)g(the)g(semantics)g(of)g(the)g
(combined)f(statement)h(should)f(be.)0 1582 y(Guido)27
b(v)n(an)f(Rossum)i(spent)f(some)h(time)f(w)o(orking)f(with)i(Ja)n(v)n
(a,)h(which)e(does)g(support)f(the)i(equi)n(v)n(alent)e(of)h(combining)
e Fh(except)0 1682 y Fk(blocks)20 b(and)f(a)i Fh(finally)e
Fk(block,)g(and)h(this)h(clari\002ed)e(what)i(the)f(statement)g(should)
f(mean.)24 b(In)c(Python)f(2.5,)g(you)h(can)g(no)n(w)f(write:)236
1920 y Fg(try:)416 2011 y(block-1)43 b(...)236 2102 y(except)h
(Exception1:)416 2194 y(handler-1)f(...)236 2285 y(except)h
(Exception2:)416 2376 y(handler-2)f(...)236 2468 y(else:)416
2559 y(else-block)236 2650 y(finally:)416 2742 y(final-block)0
3028 y Fk(The)16 b(code)g(in)h Ff(bloc)n(k-1)f Fk(is)h(e)o(x)o(ecuted.)
22 b(If)17 b(the)f(code)g(raises)h(an)g(e)o(xception,)e(the)i(v)n
(arious)e Fh(except)i Fk(blocks)f(are)g(tested:)24 b(if)17
b(the)f(e)o(xception)0 3128 y(is)23 b(of)e(class)i Fh(Exception1)p
Fk(,)e Ff(handler)n(-1)f Fk(is)i(e)o(x)o(ecuted;)f(otherwise)g(if)h
(it')-5 b(s)23 b(of)f(class)h Fh(Exception2)p Fk(,)d
Ff(handler)n(-2)g Fk(is)j(e)o(x)o(ecuted,)d(and)0 3228
y(so)h(forth.)i(If)d(no)g(e)o(xception)f(is)i(raised,)e(the)i
Ff(else-bloc)n(k)g Fk(is)g(e)o(x)o(ecuted.)0 3375 y(No)31
b(matter)g(what)g(happened)e(pre)n(viously)-5 b(,)32
b(the)f Ff(\002nal-bloc)n(k)f Fk(is)j(e)o(x)o(ecuted)c(once)h(the)i
(code)e(block)g(is)j(complete)d(and)g(an)o(y)h(raised)0
3474 y(e)o(xceptions)22 b(handled.)34 b(Ev)o(en)22 b(if)i(there')-5
b(s)24 b(an)f(error)g(in)h(an)f(e)o(xception)f(handler)g(or)i(the)f
Ff(else-bloc)n(k)i Fk(and)e(a)h(ne)n(w)g(e)o(xception)d(is)k(raised,)0
3574 y(the)20 b(code)g(in)g(the)g Ff(\002nal-bloc)n(k)g
Fk(is)h(still)g(run.)0 3721 y Fi(See)g(Also:)0 3868 y
Fk(PEP)g(341,)e(\223)p Ff(Unifying)g(try-e)n(xcept)h(and)f
(try-\002nally)p Fk(\224)208 3967 y(PEP)h(written)g(by)g(Geor)o(g)f
(Brandl;)h(implementation)e(by)h(Thomas)h(Lee.)0 4295
y Fl(7)120 b(PEP)32 b(342:)43 b(Ne)n(w)34 b(Gener)o(ator)h(F)l(eatures)
0 4527 y Fk(Python)22 b(2.5)h(adds)g(a)h(simple)f(w)o(ay)h(to)f(pass)h
(v)n(alues)f Ff(into)g Fk(a)h(generator)-5 b(.)33 b(As)24
b(introduced)d(in)j(Python)e(2.3,)h(generators)f(only)h(produce)0
4627 y(output;)16 b(once)g(a)h(generator')-5 b(s)15 b(code)g(w)o(as)j
(in)m(v)n(ok)o(ed)c(to)j(create)f(an)g(iterator)m(,)g(there)g(w)o(as)h
(no)f(w)o(ay)g(to)h(pass)g(an)o(y)e(ne)n(w)h(information)e(into)j(the)0
4727 y(function)i(when)i(its)h(e)o(x)o(ecution)d(is)k(resumed.)j
(Sometimes)21 b(the)g(ability)g(to)h(pass)g(in)f(some)g(information)e
(w)o(ould)h(be)h(useful.)28 b(Hackish)0 4826 y(solutions)20
b(to)h(this)g(include)e(making)h(the)g(generator')-5
b(s)19 b(code)h(look)g(at)h(a)g(global)f(v)n(ariable)f(and)h(then)g
(changing)f(the)i(global)e(v)n(ariable')-5 b(s)0 4926
y(v)n(alue,)19 b(or)h(passing)g(in)g(some)g(mutable)g(object)f(that)i
(callers)f(then)g(modify)-5 b(.)0 5073 y(T)e(o)20 b(refresh)g(your)f
(memory)f(of)i(basic)g(generators,)f(here')-5 b(s)20
b(a)g(simple)g(e)o(xample:)p 0 5549 3901 4 v 3854 5649
a Fe(7)p eop end
%%Page: 8 8
TeXDict begin 8 7 bop 236 174 a Fg(def)45 b(counter)e(\(maximum\):)416
266 y(i)h(=)h(0)416 357 y(while)f(i)g(<)h(maximum:)595
448 y(yield)f(i)595 540 y(i)h(+=)f(1)0 826 y Fk(When)24
b(you)g(call)h Fh(counter\(10\))p Fk(,)e(the)i(result)f(is)h(an)g
(iterator)e(that)i(returns)e(the)i(v)n(alues)f(from)f(0)i(up)f(to)g(9.)
38 b(On)24 b(encountering)e(the)0 926 y Fh(yield)h Fk(statement,)h(the)
f(iterator)g(returns)f(the)h(pro)o(vided)e(v)n(alue)i(and)f(suspends)h
(the)g(function')-5 b(s)22 b(e)o(x)o(ecution,)g(preserving)f(the)j
(local)0 1025 y(v)n(ariables.)48 b(Ex)o(ecution)27 b(resumes)g(on)h
(the)h(follo)n(wing)d(call)j(to)f(the)h(iterator')-5
b(s)28 b Fh(next\(\))f Fk(method,)i(picking)e(up)h(after)g(the)g
Fh(yield)0 1125 y Fk(statement.)0 1272 y(In)c(Python)g(2.3,)h
Fh(yield)f Fk(w)o(as)i(a)f(statement;)h(it)g(didn')o(t)d(return)g(an)o
(y)h(v)n(alue.)38 b(In)24 b(2.5,)h Fh(yield)f Fk(is)i(no)n(w)e(an)h(e)o
(xpression,)f(returning)e(a)0 1372 y(v)n(alue)e(that)g(can)g(be)g
(assigned)g(to)g(a)h(v)n(ariable)e(or)h(otherwise)f(operated)g(on:)236
1610 y Fg(val)45 b(=)f(\(yield)g(i\))0 1896 y Fk(I)29
b(recommend)c(that)k(you)e(al)o(w)o(ays)i(put)f(parentheses)f(around)g
(a)h Fh(yield)g Fk(e)o(xpression)f(when)h(you')l(re)e(doing)h
(something)g(with)i(the)0 1996 y(returned)21 b(v)n(alue,)i(as)h(in)f
(the)g(abo)o(v)o(e)f(e)o(xample.)32 b(The)23 b(parentheses)f(aren')o(t)
g(al)o(w)o(ays)h(necessary)-5 b(,)23 b(b)n(ut)g(it')-5
b(s)24 b(easier)g(to)f(al)o(w)o(ays)g(add)g(them)0 2095
y(instead)d(of)g(ha)n(ving)f(to)h(remember)f(when)g(the)o(y')l(re)g
(needed.)0 2242 y(\(PEP)24 b(342)e(e)o(xplains)h(the)g(e)o(xact)g
(rules,)h(which)f(are)g(that)h(a)g Fh(yield)p Fk(-e)o(xpression)c(must)
k(al)o(w)o(ays)g(be)f(parenthesized)f(e)o(xcept)g(when)h(it)0
2342 y(occurs)c(at)h(the)g(top-le)n(v)o(el)f(e)o(xpression)f(on)h(the)h
(right-hand)d(side)k(of)e(an)h(assignment.)k(This)c(means)f(you)g(can)h
(write)g Fh(val)49 b(=)h(yield)0 2442 y(i)21 b Fk(b)n(ut)f(ha)n(v)o(e)f
(to)i(use)f(parentheses)f(when)h(there')-5 b(s)20 b(an)g(operation,)e
(as)j(in)f Fh(val)50 b(=)f(\(yield)g(i\))g(+)h(12)p Fk(.\))0
2588 y(V)-9 b(alues)25 b(are)g(sent)g(into)f(a)i(generator)d(by)h
(calling)h(its)g Fh(send\()p Ff(value)p Fh(\))f Fk(method.)37
b(The)25 b(generator')-5 b(s)23 b(code)h(is)i(then)e(resumed)g(and)h
(the)0 2688 y Fh(yield)20 b Fk(e)o(xpression)e(returns)i(the)g
(speci\002ed)g Ff(value)p Fk(.)k(If)c(the)g(re)o(gular)f
Fh(next\(\))h Fk(method)e(is)k(called,)d(the)i Fh(yield)e
Fk(returns)h Fh(None)p Fk(.)0 2835 y(Here')-5 b(s)20
b(the)h(pre)n(vious)d(e)o(xample,)h(modi\002ed)g(to)h(allo)n(w)g
(changing)e(the)j(v)n(alue)e(of)h(the)g(internal)g(counter)-5
b(.)236 2982 y Fg(def)45 b(counter)e(\(maximum\):)416
3073 y(i)h(=)h(0)416 3165 y(while)f(i)g(<)h(maximum:)595
3256 y(val)f(=)h(\(yield)f(i\))595 3347 y(#)h(If)f(value)g(provided,)f
(change)h(counter)595 3438 y(if)g(val)h(is)f(not)h(None:)774
3530 y(i)g(=)g(val)595 3621 y(else:)774 3712 y(i)g(+=)f(1)0
3999 y Fk(And)20 b(here')-5 b(s)20 b(an)g(e)o(xample)f(of)h(changing)e
(the)i(counter:)p 0 5549 3901 4 v 0 5649 a Fe(8)2437
b(7)83 b(PEP)24 b(342:)29 b(Ne)n(w)24 b(Gener)o(ator)f(F)n(eatures)p
eop end
%%Page: 9 9
TeXDict begin 9 8 bop 236 83 a Fg(>>>)45 b(it)f(=)h(counter\(10\))236
174 y(>>>)g(print)f(it.next\(\))236 266 y(0)236 357 y(>>>)h(print)f
(it.next\(\))236 448 y(1)236 540 y(>>>)h(print)f(it.send\(8\))236
631 y(8)236 722 y(>>>)h(print)f(it.next\(\))236 814 y(9)236
905 y(>>>)h(print)f(it.next\(\))236 996 y(Traceback)g(\(most)g(recent)f
(call)i(last\):)326 1088 y(File)f(``t.py'',)f(line)i(15,)f(in)g(?)416
1179 y(print)g(it.next\(\))236 1270 y(StopIteration)0
1557 y Fh(yield)25 b Fk(will)h(usually)f(return)f Fh(None)p
Fk(,)j(so)f(you)e(should)h(al)o(w)o(ays)h(check)e(for)h(this)h(case.)41
b(Don')o(t)24 b(just)i(use)g(its)g(v)n(alue)f(in)h(e)o(xpressions)0
1656 y(unless)20 b(you')l(re)f(sure)h(that)g(the)g Fh(send\(\))g
Fk(method)f(will)i(be)f(the)g(only)f(method)g(used)h(to)g(resume)g
(your)f(generator)f(function.)0 1803 y(In)i(addition)f(to)h
Fh(send\(\))p Fk(,)g(there)f(are)h(tw)o(o)h(other)e(ne)n(w)h(methods)f
(on)h(generators:)125 2025 y Fd(\017)41 b Fh(throw\()p
Ff(type)p Fh(,)47 b Ff(value)p Fh(=None,)h Ff(tr)o(acebac)n(k)q
Fh(=None\))17 b Fk(is)j(used)f(to)g(raise)g(an)g(e)o(xception)e(inside)
i(the)g(generator;)f(the)h(e)o(xcep-)208 2125 y(tion)g(is)j(raised)e
(by)f(the)i Fh(yield)e Fk(e)o(xpression)g(where)h(the)g(generator')-5
b(s)18 b(e)o(x)o(ecution)g(is)k(paused.)125 2288 y Fd(\017)41
b Fh(close\(\))19 b Fk(raises)h(a)h(ne)n(w)e Fh(GeneratorExit)g
Fk(e)o(xception)f(inside)h(the)h(generator)e(to)i(terminate)g(the)g
(iteration.)k(On)c(recei)n(v-)208 2387 y(ing)j(this)h(e)o(xception,)f
(the)h(generator')-5 b(s)22 b(code)h(must)h(either)f(raise)h
Fh(GeneratorExit)e Fk(or)h Fh(StopIteration)p Fk(.)34
b(Catching)208 2487 y(the)28 b Fh(GeneratorExit)f Fk(e)o(xception)g
(and)h(returning)e(a)j(v)n(alue)f(is)i(ille)o(gal)e(and)g(will)h
(trigger)e(a)i Fh(RuntimeError)p Fk(;)j(if)d(the)208
2586 y(function)16 b(raises)j(some)g(other)e(e)o(xception,)g(that)i(e)o
(xception)d(is)k(propagated)15 b(to)k(the)g(caller)-5
b(.)24 b Fh(close\(\))18 b Fk(will)h(also)g(be)g(called)f(by)208
2686 y(Python')-5 b(s)19 b(garbage)f(collector)h(when)h(the)g
(generator)e(is)j(garbage-collected.)208 2817 y(If)47
b(you)f(need)g(to)i(run)e(cleanup)g(code)g(when)h(a)g
Fh(GeneratorExit)f Fk(occurs,)52 b(I)c(suggest)f(using)f(a)i
Fh(try:)99 b(...)208 2917 y(finally:)24 b Fk(suite)c(instead)g(of)g
(catching)f Fh(GeneratorExit)p Fk(.)0 3139 y(The)c(cumulati)n(v)o(e)f
(ef)n(fect)h(of)g(these)h(changes)e(is)i(to)g(turn)f(generators)f(from)
g(one-w)o(ay)g(producers)g(of)h(information)e(into)i(both)g(producers)0
3238 y(and)20 b(consumers.)0 3385 y(Generators)27 b(also)i(become)e
Ff(cor)l(outines)p Fk(,)j(a)f(more)e(generalized)g(form)h(of)g
(subroutines.)48 b(Subroutines)27 b(are)h(entered)f(at)i(one)f(point)0
3485 y(and)22 b(e)o(xited)g(at)h(another)e(point)h(\(the)g(top)g(of)h
(the)f(function,)g(and)g(a)h Fh(return)f Fk(statement\),)g(b)n(ut)h
(coroutines)e(can)h(be)h(entered,)f(e)o(xited,)0 3584
y(and)g(resumed)g(at)h(man)o(y)f(dif)n(ferent)f(points)h(\(the)g
Fh(yield)h Fk(statements\).)32 b(W)-7 b(e')o(ll)24 b(ha)n(v)o(e)e(to)h
(\002gure)f(out)h(patterns)f(for)g(using)g(coroutines)0
3684 y(ef)n(fecti)n(v)o(ely)c(in)j(Python.)0 3831 y(The)h(addition)e
(of)i(the)g Fh(close\(\))g Fk(method)e(has)j(one)e(side)h(ef)n(fect)g
(that)g(isn')o(t)g(ob)o(vious.)28 b Fh(close\(\))22 b
Fk(is)h(called)f(when)f(a)i(generator)d(is)0 3931 y(garbage-collected,)
13 b(so)j(this)h(means)f(the)g(generator')-5 b(s)15 b(code)g(gets)i
(one)e(last)i(chance)e(to)i(run)e(before)g(the)h(generator)e(is)j
(destro)o(yed.)22 b(This)0 4030 y(last)27 b(chance)e(means)h(that)g
Fh(try...finally)e Fk(statements)i(in)h(generators)d(can)i(no)n(w)g(be)
g(guaranteed)d(to)k(w)o(ork;)h(the)e Fh(finally)0 4130
y Fk(clause)f(will)g(no)n(w)f(al)o(w)o(ays)h(get)g(a)g(chance)f(to)g
(run.)38 b(The)24 b(syntactic)g(restriction)g(that)h(you)f(couldn')o(t)
e(mix)i Fh(yield)h Fk(statements)f(with)0 4229 y(a)30
b Fh(try...finally)e Fk(suite)i(has)g(therefore)d(been)i(remo)o(v)o
(ed.)51 b(This)30 b(seems)g(lik)o(e)g(a)g(minor)e(bit)i(of)f(language)f
(tri)n(via,)j(b)n(ut)f(using)0 4329 y(generators)19 b(and)i
Fh(try...finally)e Fk(is)j(actually)e(necessary)g(in)i(order)d(to)i
(implement)f(the)h Fh(with)g Fk(statement)g(described)e(by)i(PEP)0
4429 y(343.)j(I')o(ll)c(look)g(at)g(this)h(ne)n(w)f(statement)g(in)g
(the)h(follo)n(wing)d(section.)0 4576 y(Another)24 b(e)n(v)o(en)h(more)
g(esoteric)h(ef)n(fect)f(of)g(this)h(change:)35 b(pre)n(viously)-5
b(,)25 b(the)h Fh(gi_frame)f Fk(attrib)n(ute)g(of)g(a)i(generator)c(w)o
(as)k(al)o(w)o(ays)f(a)0 4675 y(frame)19 b(object.)25
b(It')-5 b(s)21 b(no)n(w)e(possible)h(for)g Fh(gi_frame)f
Fk(to)h(be)g Fh(None)g Fk(once)g(the)g(generator)e(has)j(been)e(e)o
(xhausted.)0 4822 y Fi(See)i(Also:)0 4969 y Fk(PEP)g(342,)e(\223)p
Ff(Cor)l(outines)h(via)g(Enhanced)e(Gener)o(ator)o(s)p
Fk(\224)208 5069 y(PEP)27 b(written)f(by)g(Guido)g(v)n(an)g(Rossum)h
(and)f(Phillip)h(J.)g(Eby;)j(implemented)24 b(by)j(Phillip)f(J.)i(Eby)
-5 b(.)43 b(Includes)25 b(e)o(xamples)h(of)208 5168 y(some)20
b(f)o(ancier)f(uses)i(of)f(generators)e(as)j(coroutines.)208
5299 y(Earlier)i(v)o(ersions)g(of)g(these)h(features)f(were)h(proposed)
e(in)i(PEP)g(288)f(by)h(Raymond)e(Hettinger)h(and)g(PEP)i(325)e(by)g
(Samuele)208 5399 y(Pedroni.)p 0 5549 3901 4 v 3854 5649
a Fe(9)p eop end
%%Page: 10 10
TeXDict begin 10 9 bop 0 83 a Fj(
http://en.wikipedia.o)o(rg/wi)o(ki/Co)
o(rou)o(tin)o(e)208 183 y Fk(The)19 b(W)m(ikipedia)h(entry)f(for)h
(coroutines.)0 330 y Fj(
http://www)l(.sidhe)o(.org/\230d)o(an/)o(b)n
(log)o(/a)o(rchiv)n(es/0)o(001)o(78)o(.h)o(tml)208 429
y Fk(An)g(e)o(xplanation)e(of)i(coroutines)e(from)h(a)i(Perl)f(point)g
(of)g(vie)n(w)-5 b(,)19 b(written)h(by)g(Dan)g(Sugalski.)0
757 y Fl(8)120 b(PEP)32 b(343:)43 b(The)34 b('with')f(statement)0
989 y Fk(The)17 b(')p Fh(with)p Fk(')g(statement)h(clari\002es)g(code)f
(that)h(pre)n(viously)e(w)o(ould)h(use)h Fh(try...finally)e
Fk(blocks)h(to)h(ensure)f(that)h(clean-up)e(code)0 1089
y(is)k(e)o(x)o(ecuted.)j(In)c(this)g(section,)g(I')o(ll)g(discuss)h
(the)f(statement)g(as)h(it)f(will)h(commonly)d(be)i(used.)24
b(In)19 b(the)g(ne)o(xt)g(section,)g(I')o(ll)g(e)o(xamine)f(the)0
1189 y(implementation)g(details)i(and)g(sho)n(w)g(ho)n(w)g(to)g(write)g
(objects)g(for)g(use)g(with)h(this)f(statement.)0 1336
y(The)g(')p Fh(with)p Fk(')f(statement)h(is)h(a)g(ne)n(w)f
(control-\003o)n(w)e(structure)h(whose)h(basic)g(structure)g(is:)236
1574 y Fg(with)44 b(expression)g([as)g(variable]:)416
1665 y(with-block)0 1952 y Fk(The)23 b(e)o(xpression)f(is)i(e)n(v)n
(aluated,)e(and)h(it)h(should)e(result)h(in)h(an)f(object)g(that)g
(supports)f(the)h(conte)o(xt)f(management)f(protocol)h(\(that)h(is,)0
2051 y(has)d Fh(__enter__\(\))f Fk(and)h Fh(__exit__\(\))f
Fk(methods.)0 2198 y(The)25 b(object')-5 b(s)24 b Fh(__enter__\(\))g
Fk(is)i(called)e(before)g Ff(with-bloc)n(k)i Fk(is)f(e)o(x)o(ecuted)e
(and)i(therefore)e(can)i(run)f(set-up)g(code.)39 b(It)25
b(also)g(may)0 2298 y(return)d(a)i(v)n(alue)f(that)g(is)i(bound)c(to)j
(the)f(name)g Ff(variable)p Fk(,)g(if)h(gi)n(v)o(en.)33
b(\(Note)23 b(carefully)f(that)i Ff(variable)f Fk(is)h
Ff(not)f Fk(assigned)g(the)g(result)h(of)0 2397 y Ff(e)n(xpr)m(ession)p
Fk(.\))0 2544 y(After)d(e)o(x)o(ecution)e(of)j(the)f
Ff(with-bloc)n(k)h Fk(is)h(\002nished,)e(the)g(object')-5
b(s)21 b Fh(__exit__\(\))g Fk(method)f(is)i(called,)f(e)n(v)o(en)g(if)g
(the)h(block)e(raised)i(an)0 2644 y(e)o(xception,)c(and)i(can)g
(therefore)e(run)h(clean-up)g(code.)0 2791 y(T)-7 b(o)20
b(enable)g(the)g(statement)g(in)g(Python)f(2.5,)h(you)f(need)g(to)i
(add)e(the)i(follo)n(wing)d(directi)n(v)o(e)h(to)h(your)f(module:)236
3029 y Fg(from)44 b(__future__)g(import)f(with_statement)0
3315 y Fk(The)20 b(statement)g(will)h(al)o(w)o(ays)f(be)h(enabled)d(in)
j(Python)e(2.6.)0 3462 y(Some)i(standard)f(Python)h(objects)g(no)n(w)g
(support)f(the)h(conte)o(xt)g(management)e(protocol)h(and)h(can)g(be)g
(used)g(with)h(the)g(')p Fh(with)p Fk(')e(state-)0 3562
y(ment.)25 b(File)20 b(objects)g(are)h(one)e(e)o(xample:)236
3800 y Fg(with)44 b(open\('/etc/passwd',)e('r'\))i(as)h(f:)416
3891 y(for)f(line)g(in)h(f:)595 3983 y(print)f(line)595
4074 y(...)g(more)g(processing)g(code)g(...)0 4361 y
Fk(After)21 b(this)g(statement)f(has)h(e)o(x)o(ecuted,)e(the)i(\002le)g
(object)g(in)g Ff(f)33 b Fk(will)22 b(ha)n(v)o(e)e(been)g
(automatically)f(closed,)h(e)n(v)o(en)g(if)h(the)g Fh(for)g
Fk(loop)f(raised)0 4460 y(an)g(e)o(xception)e(part-w)o(ay)h(through)f
(the)j(block.)0 4607 y Fi(Note:)j Fk(In)c(this)h(case,)f
Ff(f)33 b Fk(is)21 b(the)g(same)f(object)g(created)f(by)h
Fh(open\(\))p Fk(,)f(because)h Fh(file.__enter__\(\))e
Fk(returns)h Ff(self)12 b Fk(.)0 4754 y(The)20 b Fh(threading)f
Fk(module')-5 b(s)19 b(locks)h(and)g(condition)e(v)n(ariables)i(also)g
(support)f(the)h(')p Fh(with)p Fk(')f(statement:)236
4992 y Fg(lock)44 b(=)h(threading.Lock\(\))236 5084 y(with)f(lock:)416
5175 y(#)g(Critical)g(section)f(of)i(code)416 5266 y(...)p
0 5549 3901 4 v 0 5649 a Fe(10)2561 b(8)83 b(PEP)25 b(343:)k(The)23
b('with')h(statement)p eop end
%%Page: 11 11
TeXDict begin 11 10 bop 0 83 a Fk(The)20 b(lock)g(is)h(acquired)d
(before)h(the)h(block)g(is)h(e)o(x)o(ecuted)d(and)i(al)o(w)o(ays)g
(released)g(once)f(the)i(block)e(is)i(complete.)0 230
y(The)e(ne)n(w)g Fh(localcontext\(\))e Fk(function)h(in)h(the)h
Fh(decimal)e Fk(module)g(mak)o(es)h(it)h(easy)g(to)f(sa)n(v)o(e)g(and)g
(restore)g(the)g(current)f(decimal)0 330 y(conte)o(xt,)h(which)g
(encapsulates)h(the)g(desired)f(precision)h(and)f(rounding)f
(characteristics)h(for)h(computations:)236 568 y Fg(from)44
b(decimal)g(import)g(Decimal,)f(Context,)h(localcontext)236
750 y(#)h(Displays)e(with)i(default)e(precision)h(of)g(28)g(digits)236
842 y(v)h(=)g(Decimal\('578'\))236 933 y(print)f(v.sqrt\(\))236
1116 y(with)g(localcontext\(Context\(prec=16\)\):)416
1207 y(#)g(All)h(code)f(in)g(this)g(block)g(uses)h(a)f(precision)f(of)i
(16)f(digits.)416 1298 y(#)g(The)h(original)e(context)h(is)g(restored)g
(on)g(exiting)g(the)g(block.)416 1390 y(print)g(v.sqrt\(\))0
1814 y Fc(8.1)100 b(Wr)q(iting)29 b(Conte)m(xt)f(Managers)0
2017 y Fk(Under)g(the)g(hood,)h(the)g(')p Fh(with)p Fk(')f(statement)g
(is)i(f)o(airly)e(complicated.)48 b(Most)29 b(people)f(will)h(only)f
(use)h(')p Fh(with)p Fk(')e(in)i(compan)o(y)d(with)0
2117 y(e)o(xisting)d(objects)g(and)g(don')o(t)f(need)h(to)h(kno)n(w)e
(these)i(details,)g(so)g(you)f(can)g(skip)h(the)g(rest)g(of)f(this)h
(section)f(if)h(you)f(lik)o(e.)35 b(Authors)23 b(of)0
2217 y(ne)n(w)d(objects)g(will)h(need)e(to)i(understand)d(the)i
(details)h(of)e(the)i(underlying)c(implementation)h(and)i(should)f(k)o
(eep)h(reading.)0 2363 y(A)h(high-le)n(v)o(el)d(e)o(xplanation)g(of)i
(the)g(conte)o(xt)f(management)f(protocol)g(is:)125 2593
y Fd(\017)41 b Fk(The)26 b(e)o(xpression)f(is)i(e)n(v)n(aluated)e(and)h
(should)g(result)h(in)f(an)h(object)f(called)g(a)h(\223conte)o(xt)e
(manager\224.)43 b(The)26 b(conte)o(xt)f(manager)208
2693 y(must)20 b(ha)n(v)o(e)f Fh(__enter__\(\))g Fk(and)h
Fh(__exit__\(\))f Fk(methods.)125 2859 y Fd(\017)41 b
Fk(The)26 b(conte)o(xt)g(manager')-5 b(s)26 b Fh(__enter__\(\))g
Fk(method)g(is)i(called.)45 b(The)27 b(v)n(alue)g(returned)e(is)j
(assigned)f(to)g Ff(V)-5 b(AR)p Fk(.)27 b(If)g(no)g Fh('as)208
2959 y Ff(V)-5 b(AR)p Fh(')19 b Fk(clause)i(is)g(present,)e(the)h(v)n
(alue)g(is)h(simply)f(discarded.)125 3125 y Fd(\017)41
b Fk(The)19 b(code)h(in)g Ff(BLOCK)26 b Fk(is)21 b(e)o(x)o(ecuted.)125
3291 y Fd(\017)41 b Fk(If)20 b Ff(BLOCK)26 b Fk(raises)21
b(an)f(e)o(xception,)e(the)j Fh(__exit__\()p Ff(type)p
Fh(,)47 b Ff(value)p Fh(,)h Ff(tr)o(acebac)n(k)q Fh(\))20
b Fk(is)h(called)f(with)h(the)f(e)o(xception)e(details,)208
3390 y(the)j(same)g(v)n(alues)g(returned)e(by)i Fh(sys.exc_info\(\))p
Fk(.)k(The)c(method')-5 b(s)20 b(return)g(v)n(alue)g(controls)g
(whether)g(the)h(e)o(xception)f(is)208 3490 y(re-raised:)j(an)o(y)18
b(f)o(alse)h(v)n(alue)f(re-raises)g(the)g(e)o(xception,)f(and)h
Fh(True)g Fk(will)i(result)e(in)h(suppressing)e(it.)25
b(Y)-9 b(ou')o(ll)18 b(only)g(rarely)f(w)o(ant)208 3590
y(to)k(suppress)h(the)f(e)o(xception,)f(because)h(if)h(you)f(do)g(the)h
(author)f(of)g(the)h(code)f(containing)e(the)j(')p Fh(with)p
Fk(')f(statement)g(will)i(ne)n(v)o(er)208 3689 y(realize)d(an)o(ything)
e(went)i(wrong.)125 3855 y Fd(\017)41 b Fk(If)18 b Ff(BLOCK)25
b Fk(didn')o(t)17 b(raise)i(an)g(e)o(xception,)e(the)i
Fh(__exit__\(\))f Fk(method)f(is)j(still)g(called,)f(b)n(ut)g
Ff(type)p Fk(,)g Ff(value)p Fk(,)f(and)g Ff(tr)o(acebac)n(k)i
Fk(are)208 3955 y(all)g Fh(None)p Fk(.)0 4185 y(Let')-5
b(s)17 b(think)f(through)e(an)i(e)o(xample.)23 b(I)16
b(w)o(on')o(t)f(present)h(detailed)g(code)g(b)n(ut)g(will)h(only)f(sk)o
(etch)g(the)h(methods)e(necessary)h(for)f(a)i(database)0
4284 y(that)j(supports)f(transactions.)0 4431 y(\(F)o(or)27
b(people)f(unf)o(amiliar)g(with)i(database)e(terminology:)37
b(a)28 b(set)g(of)g(changes)e(to)h(the)h(database)f(are)g(grouped)e
(into)i(a)h(transaction.)0 4531 y(T)m(ransactions)i(can)h(be)g(either)g
(committed,)h(meaning)d(that)j(all)f(the)g(changes)g(are)g(written)f
(into)h(the)g(database,)i(or)e(rolled)f(back,)0 4630
y(meaning)h(that)i(the)f(changes)g(are)h(all)g(discarded)e(and)h(the)h
(database)f(is)h(unchanged.)60 b(See)33 b(an)o(y)f(database)g(te)o
(xtbook)e(for)i(more)0 4730 y(information.\))0 4877 y(Let')-5
b(s)20 b(assume)g(there')-5 b(s)19 b(an)h(object)f(representing)e(a)j
(database)f(connection.)k(Our)c(goal)g(will)h(be)g(to)f(let)i(the)e
(user)h(write)f(code)g(lik)o(e)h(this:)p 0 5549 3901
4 v 0 5649 a Fe(8.1)83 b(Wr)q(iting)25 b(Conte)n(xt)e(Managers)2651
b(11)p eop end
%%Page: 12 12
TeXDict begin 12 11 bop 236 174 a Fg(db_connection)43
b(=)i(DatabaseConnection\(\))236 266 y(with)f(db_connection)f(as)i
(cursor:)416 357 y(cursor.execute\('insert)c(into)j(...'\))416
448 y(cursor.execute\('delete)d(from)j(...'\))416 540
y(#)g(...)h(more)f(operations)f(...)0 826 y Fk(The)26
b(transaction)f(should)g(be)h(committed)f(if)h(the)g(code)f(in)i(the)f
(block)f(runs)g(\003a)o(wlessly)i(or)f(rolled)f(back)g(if)i(there')-5
b(s)26 b(an)g(e)o(xception.)0 926 y(Here')-5 b(s)20 b(the)h(basic)f
(interf)o(ace)f(for)h Fh(DatabaseConnection)d Fk(that)k(I')o(ll)f
(assume:)236 1164 y Fg(class)44 b(DatabaseConnection:)416
1255 y(#)g(Database)g(interface)416 1347 y(def)g(cursor)g(\(self\):)595
1438 y("Returns)f(a)i(cursor)f(object)g(and)g(starts)g(a)g(new)h
(transaction")416 1529 y(def)f(commit)g(\(self\):)595
1621 y("Commits)f(current)h(transaction")416 1712 y(def)g(rollback)f
(\(self\):)595 1803 y("Rolls)h(back)g(current)g(transaction")0
2090 y Fk(The)24 b Fh(__enter__\(\))e Fk(method)h(is)h(pretty)g(easy)-5
b(,)24 b(ha)n(ving)f(only)g(to)h(start)g(a)g(ne)n(w)g(transaction.)35
b(F)o(or)24 b(this)g(application)f(the)g(resulting)0
2189 y(cursor)16 b(object)g(w)o(ould)h(be)g(a)g(useful)f(result,)i(so)f
(the)g(method)f(will)h(return)f(it.)25 b(The)16 b(user)h(can)g(then)f
(add)h Fh(as)49 b(cursor)17 b Fk(to)g(their)f(')p Fh(with)p
Fk(')0 2289 y(statement)k(to)g(bind)g(the)g(cursor)f(to)h(a)h(v)n
(ariable)e(name.)236 2527 y Fg(class)44 b(DatabaseConnection:)416
2619 y(...)416 2710 y(def)g(__enter__)f(\(self\):)595
2801 y(#)i(Code)f(to)g(start)g(a)h(new)f(transaction)595
2893 y(cursor)g(=)g(self.cursor\(\))595 2984 y(return)g(cursor)0
3270 y Fk(The)21 b Fh(__exit__\(\))e Fk(method)h(is)i(the)f(most)g
(complicated)e(because)i(it')-5 b(s)22 b(where)e(most)h(of)g(the)g(w)o
(ork)g(has)g(to)g(be)g(done.)26 b(The)21 b(method)0 3370
y(has)d(to)f(check)g(if)g(an)h(e)o(xception)d(occurred.)22
b(If)17 b(there)g(w)o(as)h(no)f(e)o(xception,)f(the)i(transaction)e(is)
i(committed.)23 b(The)17 b(transaction)f(is)i(rolled)0
3470 y(back)i(if)g(there)g(w)o(as)h(an)f(e)o(xception.)0
3616 y(In)k(the)g(code)g(belo)n(w)-5 b(,)24 b(e)o(x)o(ecution)e(will)j
(just)g(f)o(all)f(of)n(f)g(the)g(end)g(of)g(the)g(function,)f
(returning)f(the)j(def)o(ault)e(v)n(alue)h(of)g Fh(None)p
Fk(.)37 b Fh(None)24 b Fk(is)0 3716 y(f)o(alse,)f(so)g(the)f(e)o
(xception)e(will)j(be)g(re-raised)e(automatically)-5
b(.)29 b(If)22 b(you)g(wished,)g(you)f(could)h(be)g(more)f(e)o(xplicit)
h(and)g(add)f(a)i Fh(return)0 3816 y Fk(statement)d(at)h(the)f(mark)o
(ed)f(location.)236 4054 y Fg(class)44 b(DatabaseConnection:)416
4145 y(...)416 4237 y(def)g(__exit__)f(\(self,)h(type,)g(value,)g
(tb\):)595 4328 y(if)g(tb)h(is)f(None:)774 4419 y(#)h(No)f(exception,)g
(so)g(commit)774 4511 y(self.commit\(\))595 4602 y(else:)774
4693 y(#)h(Exception)e(occurred,)h(so)g(rollback.)774
4785 y(self.rollback\(\))774 4876 y(#)h(return)f(False)p
0 5549 3901 4 v 0 5649 a Fe(12)2561 b(8)83 b(PEP)25 b(343:)k(The)23
b('with')h(statement)p eop end
%%Page: 13 13
TeXDict begin 13 12 bop 0 83 a Fc(8.2)100 b(The)28 b(conte)m(xtlib)h
(module)0 286 y Fk(The)c(ne)n(w)g Fh(contextlib)f Fk(module)g(pro)o
(vides)g(some)h(functions)f(and)g(a)i(decorator)e(that)h(are)g(useful)g
(for)g(writing)g(objects)g(for)f(use)0 386 y(with)c(the)h(')p
Fh(with)p Fk(')e(statement.)0 532 y(The)i(decorator)f(is)j(called)f
Fh(contextmanager)p Fk(,)d(and)j(lets)g(you)f(write)h(a)g(single)g
(generator)e(function)g(instead)i(of)f(de\002ning)g(a)h(ne)n(w)0
632 y(class.)29 b(The)21 b(generator)e(should)h(yield)h(e)o(xactly)f
(one)h(v)n(alue.)27 b(The)21 b(code)g(up)g(to)g(the)g
Fh(yield)g Fk(will)h(be)f(e)o(x)o(ecuted)f(as)h(the)h
Fh(__enter_-)0 732 y(_\(\))e Fk(method,)f(and)g(the)h(v)n(alue)f
(yielded)h(will)g(be)g(the)g(method')-5 b(s)19 b(return)g(v)n(alue)h
(that)g(will)h(get)f(bound)e(to)i(the)g(v)n(ariable)f(in)h(the)g(')p
Fh(with)p Fk(')0 831 y(statement')-5 b(s)17 b Fh(as)g
Fk(clause,)g(if)g(an)o(y)-5 b(.)23 b(The)16 b(code)h(after)f(the)h
Fh(yield)f Fk(will)i(be)f(e)o(x)o(ecuted)e(in)i(the)f
Fh(__exit__\(\))g Fk(method.)22 b(An)o(y)16 b(e)o(xception)0
931 y(raised)k(in)g(the)h(block)e(will)i(be)f(raised)g(by)g(the)g
Fh(yield)g Fk(statement.)0 1078 y(Our)g(database)f(e)o(xample)g(from)g
(the)i(pre)n(vious)d(section)i(could)f(be)i(written)e(using)h(this)h
(decorator)d(as:)236 1316 y Fg(from)44 b(contextlib)g(import)f
(contextmanager)236 1499 y(@contextmanager)236 1590 y(def)i
(db_transaction)d(\(connection\):)416 1681 y(cursor)h(=)i
(connection.cursor\(\))416 1773 y(try:)595 1864 y(yield)f(cursor)416
1955 y(except:)595 2047 y(connection.rollback\(\))595
2138 y(raise)416 2229 y(else:)595 2321 y(connection.commit\(\))236
2503 y(db)h(=)f(DatabaseConnection\(\))236 2595 y(with)g
(db_transaction\(db\))e(as)j(cursor:)416 2686 y(...)0
2972 y Fk(The)23 b Fh(contextlib)f Fk(module)g(also)i(has)f(a)h
Fh(nested\()p Ff(mgr1)p Fh(,)48 b Ff(mgr2)p Fh(,)h(...\))34
b Fk(function)22 b(that)h(combines)f(a)i(number)e(of)h(conte)o(xt)0
3072 y(managers)i(so)h(you)f(don')o(t)g(need)g(to)h(write)g(nested)g(')
p Fh(with)p Fk(')f(statements.)42 b(In)26 b(this)h(e)o(xample,)f(the)g
(single)f(')p Fh(with)p Fk(')h(statement)f(both)0 3172
y(starts)c(a)g(database)e(transaction)g(and)h(acquires)f(a)i(thread)e
(lock:)236 3410 y Fg(lock)44 b(=)h(threading.Lock\(\))236
3501 y(with)f(nested)g(\(db_transaction\(db\),)e(lock\))i(as)g
(\(cursor,)g(locked\):)416 3592 y(...)0 3879 y Fk(Finally)-5
b(,)16 b(the)f Fh(closing\()p Ff(object)q Fh(\))f Fk(function)g
(returns)g Ff(object)j Fk(so)f(that)f(it)i(can)e(be)g(bound)f(to)i(a)g
(v)n(ariable,)f(and)g(calls)h Ff(object)q Fh(.close\(\))0
3979 y Fk(at)21 b(the)f(end)g(of)f(the)i(block.)236 4217
y Fg(import)44 b(urllib,)g(sys)236 4308 y(from)g(contextlib)g(import)f
(closing)236 4491 y(with)h(closing\(urllib.urlopen\('
http://www.yahoo.)
o(com'\)\))38 b(as)45 b(f:)416 4582 y(for)f(line)g(in)h(f:)595
4674 y(sys.stdout.write\(line\))0 4961 y Fi(See)21 b(Also:)0
5108 y Fk(PEP)g(343,)e(\223)p Ff(The)h(\223with\224)h(statement)p
Fk(\224)208 5207 y(PEP)k(written)f(by)h(Guido)e(v)n(an)i(Rossum)f(and)h
(Nick)f(Coghlan;)i(implemented)d(by)h(Mik)o(e)h(Bland,)g(Guido)f(v)n
(an)g(Rossum,)i(and)208 5307 y(Neal)18 b(Norwitz.)24
b(The)18 b(PEP)h(sho)n(ws)g(the)f(code)g(generated)f(for)g(a)i(')p
Fh(with)p Fk(')f(statement,)g(which)g(can)g(be)g(helpful)g(in)g
(learning)f(ho)n(w)p 0 5549 3901 4 v 0 5649 a Fe(8.2)83
b(The)24 b(conte)n(xtlib)f(module)2801 b(13)p eop end
%%Page: 14 14
TeXDict begin 14 13 bop 208 83 a Fk(the)20 b(statement)g(w)o(orks.)0
230 y Fj(../lib/module-conte)n(xtlib)l(.h)o(tml)208 330
y Fk(The)f(documentation)f(for)h(the)h Fh(contextlib)f
Fk(module.)0 657 y Fl(9)120 b(PEP)32 b(352:)43 b(Exceptions)34
b(as)g(Ne)n(w-Style)f(Classes)0 890 y Fk(Exception)17
b(classes)j(can)f(no)n(w)f(be)h(ne)n(w-style)f(classes,)i(not)e(just)h
(classic)h(classes,)g(and)e(the)h(b)n(uilt-in)f Fh(Exception)g
Fk(class)i(and)e(all)i(the)0 989 y(standard)f(b)n(uilt-in)h(e)o
(xceptions)e(\()p Fh(NameError)p Fk(,)h Fh(ValueError)p
Fk(,)f(etc.\))25 b(are)20 b(no)n(w)g(ne)n(w-style)g(classes.)0
1136 y(The)g(inheritance)e(hierarchy)g(for)i(e)o(xceptions)e(has)j
(been)e(rearranged)f(a)j(bit.)k(In)20 b(2.5,)f(the)h(inheritance)f
(relationships)g(are:)236 1283 y Fg(BaseException)312
b(#)45 b(New)f(in)g(Python)g(2.5)236 1374 y(|-)h(KeyboardInterrupt)236
1466 y(|-)g(SystemExit)236 1557 y(|-)g(Exception)371
1648 y(|-)f(\(all)g(other)g(current)g(built-in)g(exceptions\))0
1935 y Fk(This)c(rearrangement)d(w)o(as)k(done)e(because)g(people)g
(often)g(w)o(ant)h(to)h(catch)e(all)i(e)o(xceptions)d(that)i(indicate)g
(program)e(errors.)0 2035 y Fh(KeyboardInterrupt)24 b
Fk(and)j Fh(SystemExit)f Fk(aren')o(t)g(errors,)h(though,)g(and)g
(usually)f(represent)g(an)h(e)o(xplicit)f(action)h(such)g(as)0
2134 y(the)e(user)f(hitting)g(Control-C)g(or)h(code)f(calling)g
Fh(sys.exit\(\))p Fk(.)37 b(A)25 b(bare)f Fh(except:)34
b Fk(will)25 b(catch)f(all)i(e)o(xceptions,)e(so)h(you)e(com-)0
2234 y(monly)c(need)g(to)i(list)g Fh(KeyboardInterrupt)d
Fk(and)h Fh(SystemExit)g Fk(in)i(order)d(to)j(re-raise)e(them.)25
b(The)20 b(usual)g(pattern)f(is:)236 2472 y Fg(try:)416
2563 y(...)236 2655 y(except)44 b(\(KeyboardInterrupt,)e(SystemExit\):)
416 2746 y(raise)236 2837 y(except:)416 2929 y(#)i(Log)h(error...)416
3020 y(#)f(Continue)g(running)f(program...)0 3306 y Fk(In)22
b(Python)f(2.5,)g(you)h(can)g(no)n(w)f(write)h Fh(except)49
b(Exception)21 b Fk(to)h(achie)n(v)o(e)f(the)h(same)h(result,)f
(catching)f(all)i(the)f(e)o(xceptions)e(that)0 3406 y(usually)e
(indicate)g(errors)g(b)n(ut)g(lea)n(ving)g Fh(KeyboardInterrupt)e
Fk(and)i Fh(SystemExit)g Fk(alone.)23 b(As)d(in)e(pre)n(vious)f(v)o
(ersions,)h(a)h(bare)0 3506 y Fh(except:)24 b Fk(still)e(catches)e(all)
h(e)o(xceptions.)0 3653 y(The)29 b(goal)g(for)f(Python)h(3.0)f(is)j(to)
e(require)f(an)o(y)g(class)j(raised)e(as)h(an)f(e)o(xception)f(to)h
(deri)n(v)o(e)f(from)g Fh(BaseException)g Fk(or)h(some)0
3752 y(descendant)23 b(of)i Fh(BaseException)p Fk(,)f(and)h(future)f
(releases)h(in)g(the)g(Python)f(2.x)h(series)g(may)g(be)o(gin)f(to)h
(enforce)e(this)j(constraint.)0 3852 y(Therefore,)20
b(I)i(suggest)g(you)f(be)o(gin)g(making)g(all)h(your)f(e)o(xception)f
(classes)j(deri)n(v)o(e)e(from)g Fh(Exception)g Fk(no)n(w)-5
b(.)30 b(It')-5 b(s)22 b(been)g(suggested)0 3951 y(that)g(the)g(bare)g
Fh(except:)28 b Fk(form)21 b(should)g(be)h(remo)o(v)o(ed)d(in)k(Python)
e(3.0,)g(b)n(ut)h(Guido)f(v)n(an)h(Rossum)g(hasn')o(t)f(decided)g
(whether)g(to)h(do)0 4051 y(this)f(or)f(not.)0 4198 y(Raising)g(of)f
(strings)h(as)g(e)o(xceptions,)e(as)j(in)e(the)h(statement)f
Fh(raise)49 b("Error)g(occurred")p Fk(,)18 b(is)j(deprecated)d(in)i
(Python)e(2.5)h(and)0 4298 y(will)i(trigger)e(a)i(w)o(arning.)i(The)d
(aim)h(is)g(to)f(be)g(able)g(to)h(remo)o(v)o(e)d(the)i(string-e)o
(xception)d(feature)i(in)i(a)f(fe)n(w)g(releases.)0 4444
y Fi(See)h(Also:)0 4591 y Fk(PEP)g(352,)e(\223)p Ff(Requir)m(ed)g
(Super)m(class)g(for)i(Exceptions)p Fk(\224)208 4691
y(PEP)f(written)g(by)g(Brett)h(Cannon)e(and)h(Guido)f(v)n(an)g(Rossum;)
i(implemented)d(by)i(Brett)h(Cannon.)0 5018 y Fl(10)120
b(PEP)33 b(353:)43 b(Using)34 b(ssiz)n(e)p 1416 5018
36 4 v 42 w(t)g(as)f(the)h(inde)l(x)h(type)0 5251 y Fk(A)20
b(wide-ranging)d(change)h(to)i(Python')-5 b(s)19 b(C)h(API,)g(using)f
(a)h(ne)n(w)f Fh(Py_ssize_t)g Fk(type)g(de\002nition)f(instead)i(of)f
Fh(int)p Fk(,)g(will)i(permit)e(the)0 5351 y(interpreter)g(to)h(handle)
f(more)g(data)h(on)g(64-bit)f(platforms.)24 b(This)c(change)f(doesn')o
(t)g(af)n(fect)h(Python')-5 b(s)19 b(capacity)g(on)h(32-bit)f
(platforms.)p 0 5549 3901 4 v 0 5649 a Fe(14)2129 b(10)83
b(PEP)25 b(353:)k(Using)23 b(ssiz)o(e)p 3205 5649 25
4 v 29 w(t)g(as)g(the)g(inde)n(x)g(type)p eop end
%%Page: 15 15
TeXDict begin 15 14 bop 0 83 a Fk(V)-9 b(arious)20 b(pieces)h(of)g(the)
g(Python)f(interpreter)g(used)h(C')-5 b(s)22 b Fh(int)f
Fk(type)g(to)g(store)g(sizes)h(or)f(counts;)g(for)f(e)o(xample,)g(the)h
(number)e(of)i(items)0 183 y(in)i(a)h(list)g(or)e(tuple)h(were)g
(stored)f(in)i(an)e Fh(int)p Fk(.)34 b(The)23 b(C)g(compilers)f(for)h
(most)g(64-bit)f(platforms)g(still)i(de\002ne)e Fh(int)h
Fk(as)h(a)f(32-bit)f(type,)0 282 y(so)i(that)g(meant)f(that)h(lists)h
(could)e(only)g(hold)g(up)g(to)h Fh(2)1580 297 y(**)1680
282 y(31)49 b(-)g(1)24 b Fk(=)h(2147483647)19 b(items.)36
b(\(There)23 b(are)g(actually)g(a)i(fe)n(w)e(dif)n(ferent)0
382 y(programming)18 b(models)k(that)f(64-bit)g(C)i(compilers)e(can)g
(use)h(\226)g(see)g Fj(
http://www)l(.unix.org/v)n(ersion2)o(/wha)o
(tsne)n(w/l)o(p6)o(4)p 3450 382 23 4 v 21 w(wp)m(.html)f
Fk(for)g(a)0 482 y(discussion)f(\226)g(b)n(ut)g(the)g(most)h(commonly)d
(a)n(v)n(ailable)h(model)h(lea)n(v)o(es)g Fh(int)g Fk(as)h(32)f
(bits.\))0 628 y(A)30 b(limit)f(of)g(2147483647)c(items)30
b(doesn')o(t)e(really)g(matter)h(on)g(a)h(32-bit)e(platform)f(because)i
(you')o(ll)f(run)h(out)g(of)f(memory)g(before)0 728 y(hitting)f(the)h
(length)f(limit.)49 b(Each)27 b(list)i(item)f(requires)f(space)h(for)f
(a)h(pointer)m(,)g(which)f(is)i(4)f(bytes,)h(plus)f(space)g(for)f(a)h
Fh(PyObject)0 828 y Fk(representing)18 b(the)i(item.)25
b(2147483647*4)15 b(is)21 b(already)f(more)f(bytes)h(than)g(a)g(32-bit)
f(address)h(space)g(can)g(contain.)0 975 y(It')-5 b(s)23
b(possible)e(to)i(address)e(that)h(much)f(memory)g(on)g(a)i(64-bit)e
(platform,)g(ho)n(we)n(v)o(er)-5 b(.)28 b(The)22 b(pointers)f(for)h(a)g
(list)h(that)f(size)h(w)o(ould)e(only)0 1074 y(require)e(16)h(GiB)h(of)
f(space,)g(so)g(it')-5 b(s)21 b(not)f(unreasonable)e(that)i(Python)f
(programmers)f(might)h(construct)g(lists)j(that)e(lar)o(ge.)k
(Therefore,)0 1174 y(the)i(Python)g(interpreter)e(had)i(to)h(be)f
(changed)e(to)j(use)g(some)f(type)g(other)f(than)h Fh(int)p
Fk(,)i(and)e(this)g(will)h(be)g(a)g(64-bit)e(type)h(on)g(64-bit)0
1273 y(platforms.)f(The)c(change)e(will)i(cause)g(incompatibilities)e
(on)i(64-bit)e(machines,)h(so)h(it)g(w)o(as)h(deemed)d(w)o(orth)h
(making)g(the)g(transition)0 1373 y(no)n(w)-5 b(,)18
b(while)g(the)h(number)e(of)h(64-bit)g(users)g(is)i(still)g(relati)n(v)
o(ely)d(small.)25 b(\(In)18 b(5)g(or)h(10)f(years,)g(we)h(may)f
Ff(all)h Fk(be)g(on)f(64-bit)f(machines,)h(and)0 1473
y(the)i(transition)g(w)o(ould)f(be)h(more)g(painful)f(then.\))0
1620 y(This)f(change)f(most)h(strongly)f(af)n(fects)g(authors)g(of)h(C)
h(e)o(xtension)e(modules.)23 b(Python)17 b(strings)g(and)h(container)e
(types)i(such)g(as)h(lists)g(and)0 1719 y(tuples)25 b(no)n(w)f(use)h
Fh(Py_ssize_t)f Fk(to)h(store)f(their)h(size.)39 b(Functions)24
b(such)h(as)g Fh(PyList_Size\(\))e Fk(no)n(w)h(return)g
Fh(Py_ssize_t)p Fk(.)0 1819 y(Code)c(in)g(e)o(xtension)f(modules)g(may)
h(therefore)e(need)i(to)g(ha)n(v)o(e)g(some)g(v)n(ariables)f(changed)g
(to)h Fh(Py_ssize_t)p Fk(.)0 1966 y(The)33 b Fh(PyArg_ParseTuple\(\))d
Fk(and)j Fh(Py_BuildValue\(\))e Fk(functions)h(ha)n(v)o(e)g(a)i(ne)n(w)
f(con)m(v)o(ersion)e(code,)k(`)p Fh(n)p Fk(',)h(for)d
Fh(Py_-)0 2065 y(ssize_t)p Fk(.)51 b Fh(PyArg_ParseTuple\(\))p
Fk(')-5 b(s)27 b(`)p Fh(s#)p Fk(')i(and)g(`)p Fh(t#)p
Fk(')g(still)h(output)e Fh(int)h Fk(by)g(def)o(ault,)i(b)n(ut)e(you)f
(can)h(de\002ne)g(the)h(macro)0 2165 y Fh(PY_SSIZE_T_CLEAN)18
b Fk(before)h(including)f(`)p Fj(Python.h)p Fk(')g(to)i(mak)o(e)g(them)
g(return)f Fh(Py_ssize_t)p Fk(.)0 2312 y(PEP)26 b(353)f(has)h(a)g
(section)g(on)f(con)m(v)o(ersion)e(guidelines)i(that)g(e)o(xtension)g
(authors)f(should)h(read)g(to)h(learn)f(about)g(supporting)f(64-bit)0
2411 y(platforms.)0 2558 y Fi(See)d(Also:)0 2705 y Fk(PEP)g(353,)e
(\223)p Ff(Using)h(ssize)p 747 2705 25 4 v 31 w(t)g(as)h(the)f(inde)n
(x)g(type)p Fk(\224)208 2805 y(PEP)g(written)g(and)g(implemented)e(by)i
(Martin)g(v)n(on)f(L)7 b(\250)-35 b(owis.)0 3132 y Fl(11)120
b(PEP)33 b(357:)43 b(The)34 b(')p 1072 3132 36 4 v 1115
3132 V 86 w(inde)l(x)p 1439 3132 V 1483 3132 V 87 w(')f(method)0
3365 y Fk(The)17 b(NumPy)f(de)n(v)o(elopers)f(had)i(a)h(problem)d(that)
i(could)g(only)f(be)h(solv)o(ed)f(by)h(adding)f(a)h(ne)n(w)g(special)h
(method,)e Fh(__index__)p Fk(.)23 b(When)0 3465 y(using)d(slice)h
(notation,)e(as)j(in)e Fh([)p Ff(start)q Fh(:)p Ff(stop)p
Fh(:)p Ff(step)p Fh(])p Fk(,)g(the)h(v)n(alues)f(of)g(the)h
Ff(start)q Fk(,)h Ff(stop)p Fk(,)e(and)g Ff(step)h Fk(inde)o(x)o(es)e
(must)i(all)g(be)f(either)g(inte)o(gers)0 3564 y(or)i(long)f(inte)o
(gers.)29 b(NumPy)21 b(de\002nes)g(a)h(v)n(ariety)f(of)h(specialized)f
(inte)o(ger)g(types)g(corresponding)e(to)j(unsigned)e(and)h(signed)g
(inte)o(gers)0 3664 y(of)f(8,)g(16,)f(32,)h(and)g(64)f(bits,)i(b)n(ut)f
(there)g(w)o(as)h(no)f(w)o(ay)g(to)g(signal)g(that)h(these)f(types)g
(could)f(be)h(used)g(as)h(slice)g(inde)o(x)o(es.)0 3811
y(Slicing)32 b(can')o(t)g(just)h(use)f(the)h(e)o(xisting)e
Fh(__int__)h Fk(method)f(because)h(that)g(method)g(is)h(also)g(used)f
(to)g(implement)g(coercion)e(to)0 3910 y(inte)o(gers.)24
b(If)18 b(slicing)h(used)g Fh(__int__)p Fk(,)f(\003oating-point)e
(numbers)h(w)o(ould)h(also)h(become)f(le)o(gal)g(slice)h(inde)o(x)o(es)
f(and)g(that')-5 b(s)19 b(clearly)g(an)0 4010 y(undesirable)f(beha)n
(viour)-5 b(.)0 4157 y(Instead,)19 b(a)i(ne)n(w)e(special)h(method)f
(called)h Fh(__index__)f Fk(w)o(as)i(added.)i(It)e(tak)o(es)f(no)g(ar)o
(guments)d(and)j(returns)f(an)h(inte)o(ger)f(gi)n(ving)g(the)0
4257 y(slice)i(inde)o(x)e(to)h(use.)25 b(F)o(or)20 b(e)o(xample:)236
4495 y Fg(class)44 b(C:)416 4586 y(def)g(__index__)f(\(self\):)595
4677 y(return)h(self.value)0 4964 y Fk(The)24 b(return)e(v)n(alue)i
(must)g(be)g(either)f(a)i(Python)e(inte)o(ger)f(or)i(long)f(inte)o(ger)
-5 b(.)36 b(The)24 b(interpreter)e(will)j(check)e(that)h(the)g(type)f
(returned)g(is)0 5063 y(correct,)c(and)h(raises)g(a)h
Fh(TypeError)e Fk(if)i(this)f(requirement)e(isn')o(t)i(met.)0
5210 y(A)g(corresponding)d Fh(nb_index)i Fk(slot)h(w)o(as)h(added)d(to)
i(the)g(C-le)n(v)o(el)g Fh(PyNumberMethods)d Fk(structure)i(to)h(let)h
(C)g(e)o(xtensions)d(imple-)0 5310 y(ment)25 b(this)g(protocol.)38
b Fh(PyNumber_Index\()p Ff(obj)p Fh(\))22 b Fk(can)i(be)h(used)g(in)g
(e)o(xtension)f(code)g(to)h(call)h(the)f Fh(__index__)f
Fk(function)f(and)p 0 5549 3901 4 v 3808 5649 a Fe(15)p
eop end
%%Page: 16 16
TeXDict begin 16 15 bop 0 83 a Fk(retrie)n(v)o(e)19 b(its)i(result.)0
230 y Fi(See)g(Also:)0 377 y Fk(PEP)g(357,)e(\223)p Ff(Allowing)g(Any)h
(Object)g(to)h(be)f(Used)g(for)h(Slicing)p Fk(\224)208
476 y(PEP)f(written)g(and)g(implemented)e(by)i(T)m(ra)n(vis)g
(Oliphant.)0 802 y Fl(12)120 b(Other)35 b(Language)i(Changes)0
1034 y Fk(Here)20 b(are)g(all)h(of)f(the)g(changes)f(that)i(Python)e
(2.5)g(mak)o(es)h(to)g(the)h(core)e(Python)g(language.)125
1252 y Fd(\017)41 b Fk(The)21 b Fh(dict)h Fk(type)f(has)i(a)f(ne)n(w)g
(hook)e(for)i(letting)f(subclasses)i(pro)o(vide)d(a)i(def)o(ault)f(v)n
(alue)g(when)h(a)g(k)o(e)o(y)g(isn')o(t)f(contained)f(in)j(the)208
1351 y(dictionary)-5 b(.)37 b(When)25 b(a)g(k)o(e)o(y)g(isn')o(t)f
(found,)h(the)g(dictionary')-5 b(s)23 b Fh(__missing__\()p
Ff(k)o(e)n(y)p Fh(\))g Fk(method)h(will)h(be)g(called.)40
b(This)25 b(hook)208 1451 y(is)i(used)g(to)g(implement)f(the)h(ne)n(w)g
Fh(defaultdict)e Fk(class)j(in)f(the)g Fh(collections)f
Fk(module.)44 b(The)27 b(follo)n(wing)e(e)o(xample)208
1551 y(de\002nes)20 b(a)g(dictionary)f(that)h(returns)f(zero)h(for)f
(an)o(y)h(missing)g(k)o(e)o(y:)444 1772 y Fg(class)44
b(zerodict)f(\(dict\):)623 1864 y(def)h(__missing__)f(\(self,)h(key\):)
802 1955 y(return)g(0)444 2138 y(d)g(=)h(zerodict\({1:1,)e(2:2}\))444
2229 y(print)h(d[1],)g(d[2])134 b(#)44 b(Prints)g(1,)h(2)444
2320 y(print)f(d[3],)g(d[4])134 b(#)44 b(Prints)g(0,)h(0)125
2621 y Fd(\017)c Fk(Both)17 b(8-bit)g(and)f(Unicode)g(strings)i(ha)n(v)
o(e)e(ne)n(w)i Fh(partition\(sep\))d Fk(and)i Fh(rpartition\(sep\))e
Fk(methods)h(that)h(simplify)208 2721 y(a)j(common)f(use)h(case.)208
2851 y(The)h Fh(find\(S\))f Fk(method)h(is)h(often)f(used)g(to)g(get)h
(an)f(inde)o(x)g(which)f(is)j(then)e(used)g(to)h(slice)g(the)f(string)h
(and)e(obtain)h(the)h(pieces)208 2951 y(that)c(are)h(before)e(and)h
(after)h(the)f(separator)-5 b(.)24 b Fh(partition\(sep\))17
b Fk(condenses)g(this)i(pattern)f(into)g(a)i(single)e(method)f(call)i
(that)208 3050 y(returns)25 b(a)h(3-tuple)f(containing)f(the)h
(substring)g(before)g(the)h(separator)m(,)f(the)h(separator)f(itself,)j
(and)d(the)h(substring)f(after)h(the)208 3150 y(separator)-5
b(.)23 b(If)18 b(the)f(separator)g(isn')o(t)h(found,)e(the)i(\002rst)g
(element)f(of)h(the)g(tuple)f(is)i(the)f(entire)f(string)h(and)f(the)h
(other)f(tw)o(o)h(elements)208 3250 y(are)23 b(empty)-5
b(.)32 b Fh(rpartition\(sep\))21 b Fk(also)i(returns)f(a)i(3-tuple)e(b)
n(ut)h(starts)h(searching)e(from)g(the)h(end)f(of)h(the)g(string;)i
(the)e(`)p Fh(r)p Fk(')208 3349 y(stands)d(for)f(')l(re)n(v)o(erse'.)
208 3480 y(Some)g(e)o(xamples:)444 3701 y Fg(>>>)44 b
(\('
http://www.python.org'\).partition\('://)o('\))444
3793 y(\('http',)f('://',)h('www.python.org'\))444 3884
y(>>>)g(\('file:/usr/share/doc/index.html'\).parti)o(tion\(')o(://'\))
444 3975 y(\('file:/usr/share/doc/index.html',)39 b('',)44
b(''\))444 4066 y(>>>)g(\(u'Subject:)f(a)i(quick)f
(question'\).partition\(':'\))444 4158 y(\(u'Subject',)f(u':',)h(u')g
(a)h(quick)f(question'\))444 4249 y(>>>)g
('www.python.org'.rpartition\('.'\))444 4340 y(\('www.python',)e('.',)i
('org'\))444 4432 y(>>>)g('www.python.org'.rpartition\(':'\))444
4523 y(\('',)g('',)g('www.python.org'\))208 4793 y Fk(\(Implemented)17
b(by)j(Fredrik)f(Lundh)g(follo)n(wing)f(a)j(suggestion)e(by)g(Raymond)g
(Hettinger)-5 b(.\))125 4954 y Fd(\017)41 b Fk(The)19
b Fh(startswith\(\))g Fk(and)h Fh(endswith\(\))e Fk(methods)i(of)f
(string)h(types)g(no)n(w)g(accept)g(tuples)g(of)g(strings)g(to)g(check)
g(for)-5 b(.)444 5176 y Fg(def)44 b(is_image_file)f(\(filename\):)623
5267 y(return)h(filename.endswith\(\('.gif',)c('.jpg',)k('.tiff'\)\))p
0 5549 3901 4 v 0 5649 a Fe(16)2677 b(12)84 b(Other)22
b(Language)j(Changes)p eop end
%%Page: 17 17
TeXDict begin 17 16 bop 208 83 a Fk(\(Implemented)17
b(by)j(Geor)o(g)f(Brandl)g(follo)n(wing)g(a)h(suggestion)f(by)h(T)-7
b(om)20 b(L)-5 b(ynn.\))125 247 y Fd(\017)41 b Fk(The)18
b Fh(min\(\))g Fk(and)g Fh(max\(\))g Fk(b)n(uilt-in)g(functions)f
(gained)g(a)i Fh(key)g Fk(k)o(e)o(yw)o(ord)d(parameter)h(analogous)g
(to)i(the)f Fh(key)h Fk(ar)o(gument)d(for)208 347 y Fh(sort\(\))p
Fk(.)23 b(This)17 b(parameter)f(supplies)h(a)h(function)d(that)j(tak)o
(es)g(a)f(single)g(ar)o(gument)e(and)i(is)h(called)f(for)g(e)n(v)o(ery)
f(v)n(alue)h(in)g(the)g(list;)208 447 y Fh(min\(\))p
Fk(/)p Fh(max\(\))22 b Fk(will)i(return)e(the)h(element)g(with)g(the)h
(smallest/lar)o(gest)f(return)f(v)n(alue)h(from)f(this)i(function.)32
b(F)o(or)23 b(e)o(xample,)208 546 y(to)d(\002nd)g(the)g(longest)g
(string)g(in)g(a)g(list,)i(you)d(can)h(do:)444 769 y
Fg(L)44 b(=)h(['medium',)e('longest',)g('short'])444
861 y(#)h(Prints)g('longest')444 952 y(print)g(max\(L,)g(key=len\))444
1043 y(#)g(Prints)g('short',)g(because)f(lexicographically)f('short')i
(has)g(the)h(largest)e(value)444 1135 y(print)h(max\(L\))208
1406 y Fk(\(Contrib)n(uted)18 b(by)i(Ste)n(v)o(en)f(Bethard)h(and)f
(Raymond)g(Hettinger)-5 b(.\))125 1571 y Fd(\017)41 b
Fk(T)-7 b(w)o(o)22 b(ne)n(w)g(b)n(uilt-in)f(functions,)g
Fh(any\(\))g Fk(and)h Fh(all\(\))p Fk(,)g(e)n(v)n(aluate)f(whether)g
(an)h(iterator)f(contains)g(an)o(y)g(true)h(or)g(f)o(alse)g(v)n(alues.)
208 1670 y Fh(any\(\))15 b Fk(returns)h Fh(True)g Fk(if)h(an)o(y)e(v)n
(alue)h(returned)e(by)i(the)g(iterator)g(is)h(true;)g(otherwise)f(it)h
(will)g(return)e Fh(False)p Fk(.)24 b Fh(all\(\))15 b
Fk(returns)208 1770 y Fh(True)22 b Fk(only)g(if)h(all)g(of)g(the)g(v)n
(alues)f(returned)f(by)h(the)h(iterator)f(e)n(v)n(aluate)g(as)h(true.)
32 b(\(Suggested)22 b(by)g(Guido)g(v)n(an)g(Rossum,)h(and)208
1869 y(implemented)18 b(by)i(Raymond)e(Hettinger)-5 b(.\))125
2034 y Fd(\017)41 b Fk(The)25 b(result)h(of)g(a)g(class')-5
b(s)27 b Fh(__hash__\(\))e Fk(method)g(can)g(no)n(w)h(be)g(either)f(a)h
(long)g(inte)o(ger)e(or)i(a)g(re)o(gular)f(inte)o(ger)-5
b(.)41 b(If)26 b(a)g(long)208 2133 y(inte)o(ger)18 b(is)i(returned,)d
(the)j(hash)f(of)g(that)g(v)n(alue)g(is)h(tak)o(en.)25
b(In)19 b(earlier)f(v)o(ersions)h(the)g(hash)g(v)n(alue)g(w)o(as)h
(required)e(to)h(be)g(a)h(re)o(gular)208 2233 y(inte)o(ger)m(,)f(b)n
(ut)i(in)g(2.5)f(the)h Fh(id\(\))g Fk(b)n(uilt-in)f(w)o(as)i(changed)d
(to)i(al)o(w)o(ays)h(return)d(non-ne)o(gati)n(v)o(e)e(numbers,)j(and)g
(users)h(often)f(seem)208 2333 y(to)g(use)g Fh(id\(self\))g
Fk(in)g Fh(__hash__\(\))f Fk(methods)g(\(though)f(this)j(is)g
(discouraged\).)125 2497 y Fd(\017)41 b Fk(ASCII)20 b(is)i(no)n(w)e
(the)h(def)o(ault)e(encoding)g(for)h(modules.)25 b(It')-5
b(s)21 b(no)n(w)f(a)h(syntax)f(error)f(if)i(a)g(module)e(contains)h
(string)g(literals)h(with)208 2597 y(8-bit)h(characters)g(b)n(ut)h
(doesn')o(t)e(ha)n(v)o(e)h(an)h(encoding)e(declaration.)31
b(In)23 b(Python)e(2.4)i(this)g(triggered)e(a)i(w)o(arning,)f(not)h(a)g
(syntax)208 2696 y(error)-5 b(.)24 b(See)c(PEP)g(263)f(for)g(ho)n(w)g
(to)h(declare)f(a)h(module')-5 b(s)19 b(encoding;)f(for)h(e)o(xample,)f
(you)h(might)g(add)g(a)h(line)g(lik)o(e)g(this)g(near)g(the)208
2796 y(top)f(of)h(the)h(source)e(\002le:)444 3019 y Fg(#)44
b(-)578 3032 y(*)623 3019 y(-)h(coding:)e(latin1)h(-)1430
3032 y(*)1475 3019 y(-)125 3323 y Fd(\017)d Fk(A)22 b(ne)n(w)g(w)o
(arning,)f Fh(UnicodeWarning)p Fk(,)g(is)i(triggered)d(when)i(you)f
(attempt)h(to)g(compare)f(a)i(Unicode)e(string)g(and)h(an)g(8-bit)208
3423 y(string)k(that)h(can')o(t)f(be)h(con)m(v)o(erted)e(to)i(Unicode)f
(using)g(the)h(def)o(ault)g(ASCII)g(encoding.)43 b(The)27
b(result)g(of)g(the)g(comparison)e(is)208 3522 y(f)o(alse:)444
3654 y Fg(>>>)44 b(chr\(128\))g(==)g(unichr\(128\))133
b(#)44 b(Can't)g(convert)g(chr\(128\))g(to)g(Unicode)444
3745 y(__main__:1:)f(UnicodeWarning:)f(Unicode)i(equal)g(comparison)f
(failed)533 3837 y(to)i(convert)f(both)g(arguments)f(to)i(Unicode)e(-)i
(interpreting)e(them)533 3928 y(as)i(being)f(unequal)444
4019 y(False)444 4111 y(>>>)g(chr\(127\))g(==)g(unichr\(127\))133
b(#)44 b(chr\(127\))g(can)g(be)h(converted)444 4202 y(True)208
4474 y Fk(Pre)n(viously)31 b(this)i(w)o(ould)f(raise)h(a)g
Fh(UnicodeDecodeError)d Fk(e)o(xception,)j(b)n(ut)g(in)g(2.5)f(this)h
(could)f(result)g(in)h(puzzling)208 4573 y(problems)24
b(when)h(accessing)g(a)h(dictionary)-5 b(.)39 b(If)25
b(you)g(look)o(ed)f(up)i Fh(unichr\(128\))e Fk(and)h
Fh(chr\(128\))f Fk(w)o(as)j(being)e(used)g(as)208 4673
y(a)f(k)o(e)o(y)-5 b(,)23 b(you')l(d)f(get)i(a)g Fh(UnicodeDecodeError)
d Fk(e)o(xception.)33 b(Other)24 b(changes)e(in)i(2.5)f(resulted)h(in)f
(this)i(e)o(xception)d(being)208 4773 y(raised)e(instead)g(of)f
(suppressed)g(by)h(the)g(code)g(in)g(`)p Fj(dictobject.c)p
Fk(')e(that)i(implements)g(dictionaries.)208 4905 y(Raising)d(an)g(e)o
(xception)f(for)h(such)g(a)g(comparison)f(is)i(strictly)g(correct,)e(b)
n(ut)i(the)f(change)f(might)h(ha)n(v)o(e)f(brok)o(en)g(code,)h(so)h
(instead)208 5004 y Fh(UnicodeWarning)g Fk(w)o(as)j(introduced.)208
5136 y(\(Implemented)c(by)j(Marc-Andr)5 b(\264)-33 b(e)18
b(Lemb)n(ur)o(g.\))125 5300 y Fd(\017)41 b Fk(One)18
b(error)g(that)h(Python)e(programmers)f(sometimes)j(mak)o(e)f(is)i(for)
o(getting)c(to)j(include)f(an)g(`)p 2876 5300 23 4 v
2903 5300 V 54 w Fj(init)p 3027 5300 V 3053 5300 V 52
w(.p)n(y)p Fk(')h(module)e(in)i(a)g(package)208 5400
y(directory)-5 b(.)28 b(Deb)n(ugging)20 b(this)i(mistak)o(e)g(can)g(be)
g(confusing,)e(and)i(usually)f(requires)g(running)f(Python)h(with)h
(the)g Fi(-v)g Fk(switch)g(to)p 0 5549 3901 4 v 3808
5649 a Fe(17)p eop end
%%Page: 18 18
TeXDict begin 18 17 bop 208 83 a Fk(log)19 b(all)i(the)f(paths)f
(searched.)24 b(In)c(Python)e(2.5,)h(a)i(ne)n(w)f Fh(ImportWarning)e
Fk(w)o(arning)g(is)j(triggered)d(when)i(an)f(import)g(w)o(ould)208
183 y(ha)n(v)o(e)c(pick)o(ed)g(up)h(a)h(directory)d(as)j(a)g(package)e
(b)n(ut)h(no)g(`)p 1767 183 23 4 v 1794 183 V 53 w Fj(init)p
1917 183 V 1943 183 V 52 w(.p)n(y)p Fk(')g(w)o(as)h(found.)22
b(This)17 b(w)o(arning)e(is)i(silently)f(ignored)e(by)i(def)o(ault;)208
282 y(pro)o(vide)i(the)i Fi(-Wd)g Fk(option)f(when)g(running)f(the)i
(Python)f(e)o(x)o(ecutable)f(to)j(display)e(the)h(w)o(arning)f
(message.)25 b(\(Implemented)17 b(by)208 382 y(Thomas)i(W)-7
b(outers.\))125 548 y Fd(\017)41 b Fk(The)19 b(list)j(of)e(base)g
(classes)h(in)g(a)f(class)h(de\002nition)e(can)h(no)n(w)g(be)g(empty)-5
b(.)24 b(As)d(an)f(e)o(xample,)e(this)j(is)g(no)n(w)f(le)o(gal:)444
772 y Fg(class)44 b(C\(\):)623 863 y(pass)208 1103 y
Fk(\(Implemented)17 b(by)j(Brett)h(Cannon.\))0 1388 y
Fc(12.1)100 b(Inter)o(activ)n(e)28 b(Inter)s(preter)i(Changes)0
1591 y Fk(In)16 b(the)h(interacti)n(v)o(e)e(interpreter)m(,)g
Fh(quit)i Fk(and)f Fh(exit)g Fk(ha)n(v)o(e)g(long)g(been)g(strings)g
(so)h(that)g(ne)n(w)f(users)h(get)g(a)g(some)n(what)e(helpful)h
(message)0 1690 y(when)k(the)o(y)f(try)h(to)g(quit:)236
1928 y Fg(>>>)45 b(quit)236 2020 y('Use)f(Ctrl-D)g(\(i.e.)g(EOF\))g(to)
h(exit.')0 2306 y Fk(In)25 b(Python)f(2.5,)i Fh(quit)f
Fk(and)g Fh(exit)g Fk(are)h(no)n(w)f(objects)g(that)g(still)i(produce)c
(string)i(representations)f(of)h(themselv)o(es,)h(b)n(ut)f(are)g(also)0
2406 y(callable.)j(Ne)n(wbies)22 b(who)f(try)g Fh(quit\(\))g
Fk(or)g Fh(exit\(\))g Fk(will)h(no)n(w)f(e)o(xit)g(the)g(interpreter)f
(as)i(the)o(y)f(e)o(xpect.)27 b(\(Implemented)19 b(by)i(Geor)o(g)0
2505 y(Brandl.\))0 2652 y(The)e(Python)f(e)o(x)o(ecutable)f(no)n(w)h
(accepts)h(the)g(standard)f(long)g(options)g Fi(--help)h
Fk(and)g Fi(--v)o(ersion)p Fk(;)f(on)h(W)m(indo)n(ws,)f(it)i(also)f
(accepts)g(the)g Fi(/?)0 2752 y Fk(option)g(for)h(displaying)e(a)j
(help)f(message.)k(\(Implemented)18 b(by)i(Geor)o(g)e(Brandl.\))0
3037 y Fc(12.2)100 b(Optimizations)0 3240 y Fk(Se)n(v)o(eral)25
b(of)g(the)g(optimizations)g(were)g(de)n(v)o(eloped)e(at)j(the)f(NeedF)
o(orSpeed)f(sprint,)i(an)f(e)n(v)o(ent)g(held)g(in)h(Re)o(ykja)n(vik,)f
(Iceland,)h(from)0 3339 y(May)j(21\22628)e(2006.)50 b(The)28
b(sprint)h(focused)f(on)g(speed)h(enhancements)e(to)i(the)g(CPython)f
(implementation)f(and)h(w)o(as)i(funded)d(by)0 3439 y(EWT)22
b(LLC)g(with)f(local)h(support)e(from)g(CCP)j(Games.)28
b(Those)21 b(optimizations)f(added)h(at)g(this)h(sprint)f(are)h
(specially)f(mark)o(ed)f(in)i(the)0 3539 y(follo)n(wing)d(list.)125
3768 y Fd(\017)41 b Fk(When)16 b(the)o(y)g(were)h(introduced)d(in)j
(Python)f(2.4,)h(the)g(b)n(uilt-in)f Fh(set)h Fk(and)f
Fh(frozenset)g Fk(types)g(were)h(b)n(uilt)g(on)f(top)h(of)f(Python')-5
b(s)208 3868 y(dictionary)16 b(type.)24 b(In)19 b(2.5)f(the)g(internal)
g(data)g(structure)g(has)h(been)f(customized)f(for)h(implementing)f
(sets,)i(and)f(as)i(a)f(result)f(sets)208 3968 y(will)i(use)h(a)g
(third)e(less)i(memory)e(and)h(are)g(some)n(what)f(f)o(aster)-5
b(.)25 b(\(Implemented)18 b(by)i(Raymond)e(Hettinger)-5
b(.\))125 4134 y Fd(\017)41 b Fk(The)20 b(speed)g(of)g(some)g(Unicode)f
(operations,)g(such)h(as)h(\002nding)e(substrings,)h(string)g
(splitting,)g(and)g(character)f(map)h(encoding)208 4233
y(and)h(decoding,)e(has)j(been)f(impro)o(v)o(ed.)26 b(\(Substring)20
b(search)h(and)g(splitting)g(impro)o(v)o(ements)e(were)i(added)g(by)g
(Fredrik)f(Lundh)208 4333 y(and)g(Andre)n(w)g(Dalk)o(e)i(at)f(the)g
(NeedF)o(orSpeed)e(sprint.)28 b(Character)20 b(maps)i(were)f(impro)o(v)
o(ed)d(by)j(W)-7 b(alter)22 b(D)7 b(\250)-35 b(orw)o(ald)20
b(and)h(Martin)208 4433 y(v)n(on)e(L)7 b(\250)-35 b(owis.\))125
4599 y Fd(\017)41 b Fk(The)22 b Fh(long\()p Ff(str)r
Fh(,)50 b Ff(base)p Fh(\))22 b Fk(function)g(is)i(no)n(w)e(f)o(aster)h
(on)g(long)f(digit)h(strings)g(because)g(fe)n(wer)f(intermediate)g
(results)i(are)f(cal-)208 4698 y(culated.)i(The)20 b(peak)g(is)i(for)e
(strings)g(of)h(around)e(800\2261000)e(digits)k(where)f(the)g(function)
f(is)j(6)e(times)h(f)o(aster)-5 b(.)27 b(\(Contrib)n(uted)19
b(by)208 4798 y(Alan)h(McIntyre)e(and)i(committed)f(at)i(the)f(NeedF)o
(orSpeed)e(sprint.\))125 4964 y Fd(\017)41 b Fk(It')-5
b(s)54 b(no)n(w)g(ille)o(gal)g(to)g(mix)g(iterating)g(o)o(v)o(er)f(a)i
(\002le)f(with)h Fh(for)49 b(line)g(in)h Ff(\002le)k
Fk(and)g(calling)f(the)i(\002le)g(object')-5 b(s)208
5064 y Fh(read\(\))p Fk(/)p Fh(readline\(\))p Fk(/)p
Fh(readlines\(\))13 b Fk(methods.)23 b(Iteration)17 b(uses)i(an)f
(internal)f(b)n(uf)n(fer)g(and)g(the)h Fh(read)3451 5079
y(*)3501 5064 y(\(\))g Fk(methods)208 5163 y(don')o(t)25
b(use)i(that)g(b)n(uf)n(fer)-5 b(.)45 b(Instead)26 b(the)o(y)h(w)o
(ould)f(return)g(the)h(data)g(follo)n(wing)f(the)h(b)n(uf)n(fer)m(,)f
(causing)h(the)g(data)g(to)g(appear)f(out)208 5263 y(of)g(order)-5
b(.)45 b(Mixing)26 b(iteration)g(and)g(these)h(methods)f(will)i(no)n(w)
e(trigger)g(a)h Fh(ValueError)f Fk(from)g(the)h Fh(read)3454
5278 y(*)3504 5263 y(\(\))f Fk(method.)208 5363 y(\(Implemented)17
b(by)j(Thomas)f(W)-7 b(outers.\))p 0 5549 3901 4 v 0
5649 a Fe(18)2677 b(12)84 b(Other)22 b(Language)j(Changes)p
eop end
%%Page: 19 19
TeXDict begin 19 18 bop 125 83 a Fd(\017)41 b Fk(The)31
b Fh(struct)g Fk(module)f(no)n(w)h(compiles)g(structure)f(format)h
(strings)g(into)g(an)h(internal)e(representation)g(and)h(caches)g(this)
208 183 y(representation,)17 b(yielding)i(a)i(20\045)f(speedup.)j
(\(Contrib)n(uted)c(by)h(Bob)g(Ippolito)e(at)j(the)f(NeedF)o(orSpeed)e
(sprint.\))125 341 y Fd(\017)41 b Fk(The)28 b Fh(re)h
Fk(module)e(got)h(a)h(1)g(or)f(2\045)h(speedup)f(by)g(switching)g(to)h
(Python')-5 b(s)28 b(allocator)f(functions)h(instead)g(of)g(the)h
(system')-5 b(s)208 441 y Fh(malloc\(\))19 b Fk(and)g
Fh(free\(\))p Fk(.)25 b(\(Contrib)n(uted)18 b(by)i(Jack)g(Diederich)f
(at)i(the)f(NeedF)o(orSpeed)e(sprint.\))125 599 y Fd(\017)41
b Fk(The)27 b(code)g(generator')-5 b(s)27 b(peephole)f(optimizer)h(no)n
(w)g(performs)f(simple)i(constant)f(folding)g(in)h(e)o(xpressions.)47
b(If)27 b(you)g(write)208 698 y(something)16 b(lik)o(e)i
Fh(a)50 b(=)f(2+3)p Fk(,)19 b(the)f(code)f(generator)f(will)i(do)g(the)
g(arithmetic)f(and)g(produce)f(code)i(corresponding)c(to)k
Fh(a)50 b(=)f(5)p Fk(.)208 798 y(\(Proposed)18 b(and)i(implemented)e
(by)i(Raymond)e(Hettinger)-5 b(.\))125 956 y Fd(\017)41
b Fk(Function)14 b(calls)j(are)e(no)n(w)g(f)o(aster)h(because)f(code)g
(objects)h(no)n(w)f(k)o(eep)g(the)h(most)g(recently)e(\002nished)i
(frame)f(\(a)g(\223zombie)g(frame\224\))208 1056 y(in)26
b(an)g(internal)f(\002eld)h(of)g(the)g(code)f(object,)i(reusing)e(it)i
(the)f(ne)o(xt)f(time)h(the)g(code)g(object)f(is)i(in)m(v)n(ok)o(ed.)41
b(\(Original)25 b(patch)g(by)208 1156 y(Michael)19 b(Hudson,)g
(modi\002ed)g(by)h(Armin)f(Rigo)i(and)e(Richard)h(Jones;)g(committed)f
(at)i(the)f(NeedF)o(orSpeed)e(sprint.\))208 1284 y(Frame)29
b(objects)h(are)f(also)i(slightly)e(smaller)m(,)j(which)d(may)g(impro)o
(v)o(e)f(cache)h(locality)h(and)f(reduce)g(memory)f(usage)h(a)i(bit.)
208 1384 y(\(Contrib)n(uted)18 b(by)i(Neal)g(Norwitz.\))125
1542 y Fd(\017)41 b Fk(Python')-5 b(s)20 b(b)n(uilt-in)i(e)o(xceptions)
e(are)h(no)n(w)g(ne)n(w-style)g(classes,)i(a)f(change)f(that)h(speeds)f
(up)g(instantiation)g(considerably)-5 b(.)27 b(Ex-)208
1642 y(ception)19 b(handling)g(in)i(Python)e(2.5)h(is)i(therefore)d
(about)g(30\045)i(f)o(aster)g(than)f(in)h(2.4.)k(\(Contrib)n(uted)19
b(by)h(Richard)g(Jones,)h(Geor)o(g)208 1742 y(Brandl)e(and)h(Sean)g
(Reifschneider)f(at)i(the)f(NeedF)o(orSpeed)e(sprint.\))125
1900 y Fd(\017)41 b Fk(Importing)23 b(no)n(w)i(caches)g(the)h(paths)f
(tried,)i(recording)c(whether)i(the)o(y)g(e)o(xist)h(or)f(not)g(so)h
(that)g(the)g(interpreter)e(mak)o(es)h(fe)n(wer)208 2000
y Fh(open\(\))19 b Fk(and)h Fh(stat\(\))f Fk(calls)i(on)f(startup.)25
b(\(Contrib)n(uted)18 b(by)i(Martin)g(v)n(on)f(L)7 b(\250)-35
b(owis)21 b(and)e(Geor)o(g)g(Brandl.\))0 2323 y Fl(13)120
b(Ne)n(w)-7 b(,)34 b(Impro)n(v)m(ed,)h(and)g(Remo)n(v)m(ed)g(Modules)0
2556 y Fk(The)18 b(standard)g(library)f(recei)n(v)o(ed)g(man)o(y)h
(enhancements)e(and)i(b)n(ug)g(\002x)o(es)h(in)g(Python)e(2.5.)24
b(Here')-5 b(s)19 b(a)g(partial)f(list)i(of)e(the)h(most)g(notable)0
2656 y(changes,)h(sorted)h(alphabetically)e(by)i(module)e(name.)27
b(Consult)21 b(the)g(`)p Fj(Misc/NEWS)p Fk(')g(\002le)h(in)f(the)g
(source)f(tree)h(for)g(a)g(more)g(complete)0 2755 y(list)g(of)f
(changes,)f(or)h(look)f(through)f(the)j(SVN)f(logs)h(for)e(all)i(the)f
(details.)125 2966 y Fd(\017)41 b Fk(The)27 b Fh(audioop)g
Fk(module)g(no)n(w)g(supports)g(the)h(a-LA)-7 b(W)28
b(encoding,)f(and)h(the)g(code)f(for)g(u-LA)-7 b(W)27
b(encoding)f(has)i(been)g(im-)208 3066 y(pro)o(v)o(ed.)22
b(\(Contrib)n(uted)d(by)g(Lars)i(Immisch.\))125 3224
y Fd(\017)41 b Fk(The)35 b Fh(codecs)g Fk(module)g(gained)f(support)h
(for)g(incremental)f(codecs.)72 b(The)36 b Fh(codec.lookup\(\))d
Fk(function)i(no)n(w)g(re-)208 3323 y(turns)40 b(a)h
Fh(CodecInfo)e Fk(instance)h(instead)h(of)f(a)h(tuple.)85
b Fh(CodecInfo)40 b Fk(instances)g(beha)n(v)o(e)g(lik)o(e)g(a)h
(4-tuple)f(to)g(pre-)208 3423 y(serv)o(e)d(backw)o(ard)g(compatibility)
f(b)n(ut)j(also)f(ha)n(v)o(e)g(the)g(attrib)n(utes)g
Fh(encode)p Fk(,)k Fh(decode)p Fk(,)g Fh(incrementalencoder)p
Fk(,)208 3523 y Fh(incrementaldecoder)p Fk(,)13 b Fh(streamwriter)p
Fk(,)h(and)h Fh(streamreader)p Fk(.)22 b(Incremental)13
b(codecs)i(can)g(recei)n(v)o(e)f(input)h(and)208 3622
y(produce)20 b(output)i(in)h(multiple)f(chunks;)h(the)g(output)f(is)i
(the)f(same)g(as)g(if)g(the)g(entire)g(input)f(w)o(as)i(fed)e(to)h(the)
g(non-incremental)208 3722 y(codec.)h(See)c(the)g Fh(codecs)g
Fk(module)f(documentation)e(for)j(details.)25 b(\(Designed)19
b(and)h(implemented)e(by)i(W)-7 b(alter)21 b(D)7 b(\250)-35
b(orw)o(ald.\))125 3880 y Fd(\017)41 b Fk(The)19 b Fh(collections)g
Fk(module)g(gained)f(a)j(ne)n(w)f(type,)f Fh(defaultdict)p
Fk(,)g(that)h(subclasses)g(the)h(standard)e Fh(dict)g
Fk(type.)25 b(The)208 3980 y(ne)n(w)19 b(type)h(mostly)f(beha)n(v)o(es)
g(lik)o(e)h(a)g(dictionary)e(b)n(ut)i(constructs)f(a)i(def)o(ault)e(v)n
(alue)g(when)g(a)h(k)o(e)o(y)g(isn')o(t)f(present,)g(automatically)208
4079 y(adding)f(it)j(to)g(the)f(dictionary)e(for)i(the)g(requested)f(k)
o(e)o(y)g(v)n(alue.)208 4208 y(The)29 b(\002rst)i(ar)o(gument)d(to)i
Fh(defaultdict)p Fk(')-5 b(s)29 b(constructor)g(is)i(a)f(f)o(actory)f
(function)g(that)h(gets)g(called)g(whene)n(v)o(er)f(a)h(k)o(e)o(y)g(is)
208 4308 y(requested)20 b(b)n(ut)h(not)g(found.)27 b(This)21
b(f)o(actory)f(function)g(recei)n(v)o(es)g(no)h(ar)o(guments,)f(so)h
(you)g(can)g(use)h(b)n(uilt-in)e(type)h(constructors)208
4408 y(such)e(as)h Fh(list\(\))g Fk(or)f Fh(int\(\))p
Fk(.)25 b(F)o(or)19 b(e)o(xample,)f(you)h(can)g(mak)o(e)h(an)f(inde)o
(x)g(of)g(w)o(ords)h(based)f(on)g(their)h(initial)g(letter)g(lik)o(e)g
(this:)444 4537 y Fg(words)44 b(=)g("""Nel)g(mezzo)g(del)h(cammin)e(di)
i(nostra)f(vita)444 4628 y(mi)g(ritrovai)g(per)g(una)g(selva)g(oscura)
444 4719 y(che)g(la)h(diritta)e(via)i(era)f
(smarrita""".lower\(\).split\(\))444 4902 y(index)g(=)g
(defaultdict\(list\))444 5085 y(for)g(w)h(in)f(words:)623
5176 y(init_letter)f(=)i(w[0])623 5267 y
(index[init_letter].append\(w\))p 0 5549 3901 4 v 3808
5649 a Fe(19)p eop end
%%Page: 20 20
TeXDict begin 20 19 bop 208 83 a Fk(Printing)19 b Fh(index)h
Fk(results)g(in)h(the)f(follo)n(wing)e(output:)444 307
y Fg(defaultdict\(<type)42 b('list'>,)h({'c':)h(['cammin',)f('che'],)h
('e':)g(['era'],)802 399 y('d':)h(['del',)e('di',)h('diritta'],)f('m':)
h(['mezzo',)g('mi'],)802 490 y('l':)h(['la'],)e('o':)h(['oscura'],)f
('n':)i(['nel',)e('nostra'],)802 581 y('p':)i(['per'],)e('s':)h
(['selva',)g('smarrita'],)802 672 y('r':)h(['ritrovai'],)d('u':)i
(['una'],)g('v':)g(['vita',)g('via']})208 945 y Fk(\(Contrib)n(uted)18
b(by)i(Guido)f(v)n(an)h(Rossum.\))125 1111 y Fd(\017)41
b Fk(The)29 b Fh(deque)g Fk(double-ended)d(queue)i(type)h(supplied)g
(by)g(the)h Fh(collections)e Fk(module)g(no)n(w)h(has)h(a)g
Fh(remove\()p Ff(value)p Fh(\))208 1211 y Fk(method)21
b(that)i(remo)o(v)o(es)e(the)i(\002rst)g(occurrence)d(of)j
Ff(value)f Fk(in)h(the)g(queue,)f(raising)g Fh(ValueError)f
Fk(if)i(the)g(v)n(alue)f(isn')o(t)h(found.)208 1310 y(\(Contrib)n(uted)
18 b(by)i(Raymond)e(Hettinger)-5 b(.\))125 1476 y Fd(\017)41
b Fk(Ne)n(w)18 b(module:)k(The)c Fh(contextlib)f Fk(module)f(contains)h
(helper)g(functions)g(for)g(use)h(with)g(the)g(ne)n(w)g(')p
Fh(with)p Fk(')f(statement.)24 b(See)208 1576 y(section)c(8.2)f(for)h
(more)f(about)g(this)i(module.)125 1742 y Fd(\017)41
b Fk(Ne)n(w)22 b(module:)28 b(The)22 b Fh(cProfile)f
Fk(module)g(is)i(a)f(C)h(implementation)d(of)i(the)g(e)o(xisting)g
Fh(profile)f Fk(module)g(that)h(has)h(much)208 1842 y(lo)n(wer)j(o)o(v)
o(erhead.)43 b(The)26 b(module')-5 b(s)26 b(interf)o(ace)g(is)i(the)f
(same)g(as)h Fh(profile)p Fk(:)38 b(you)26 b(run)g Fh
(cProfile.run\('main\(\)'\))208 1941 y Fk(to)i(pro\002le)g(a)i
(function,)e(can)h(sa)n(v)o(e)g(pro\002le)f(data)h(to)f(a)i(\002le,)h
(etc.)51 b(It')-5 b(s)29 b(not)f(yet)h(kno)n(wn)e(if)i(the)g(Hotshot)f
(pro\002ler)m(,)h(which)g(is)208 2041 y(also)23 b(written)f(in)h(C)h(b)
n(ut)f(doesn')o(t)e(match)i(the)f Fh(profile)g Fk(module')-5
b(s)22 b(interf)o(ace,)h(will)g(continue)f(to)h(be)f(maintained)g(in)h
(future)208 2140 y(v)o(ersions)c(of)h(Python.)j(\(Contrib)n(uted)c(by)h
(Armin)f(Rigo.\))208 2273 y(Also,)i(the)f Fh(pstats)h
Fk(module)e(for)h(analyzing)g(the)g(data)h(measured)f(by)g(the)h
(pro\002ler)f(no)n(w)g(supports)g(directing)f(the)i(output)e(to)208
2373 y(an)o(y)g(\002le)i(object)e(by)h(supplying)f(a)h
Ff(str)m(eam)h Fk(ar)o(gument)d(to)i(the)g Fh(Stats)g
Fk(constructor)-5 b(.)23 b(\(Contrib)n(uted)c(by)h(Skip)g(Montanaro.\))
125 2539 y Fd(\017)41 b Fk(The)26 b Fh(csv)h Fk(module,)g(which)g
(parses)g(\002les)g(in)h(comma-separated)c(v)n(alue)i(format,)h(recei)n
(v)o(ed)f(se)n(v)o(eral)g(enhancements)f(and)h(a)208
2639 y(number)h(of)j(b)n(ug\002x)o(es.)52 b(Y)-9 b(ou)30
b(can)f(no)n(w)g(set)i(the)e(maximum)f(size)j(in)f(bytes)f(of)h(a)g
(\002eld)g(by)f(calling)g(the)h Fh(csv.field_-)208 2738
y(size_limit\()p Ff(ne)o(w)p 896 2738 25 4 v 27 w(limit)q
Fh(\))d Fk(function;)g(omitting)e(the)i Ff(ne)o(w)p 2052
2738 V 29 w(limit)h Fk(ar)o(gument)c(will)j(return)e(the)h
(currently-set)e(limit.)43 b(The)208 2838 y Fh(reader)23
b Fk(class)j(no)n(w)e(has)h(a)g Fh(line_num)e Fk(attrib)n(ute)h(that)h
(counts)f(the)g(number)f(of)h(physical)f(lines)i(read)f(from)g(the)g
(source;)208 2937 y(records)19 b(can)h(span)g(multiple)f(physical)g
(lines,)h(so)h Fh(line_num)e Fk(is)i(not)f(the)h(same)f(as)h(the)f
(number)e(of)i(records)f(read.)208 3070 y(The)j(CSV)i(parser)e(is)i(no)
n(w)e(stricter)h(about)f(multi-line)g(quoted)f(\002elds.)34
b(Pre)n(viously)-5 b(,)21 b(if)i(a)h(line)e(ended)g(within)h(a)g
(quoted)e(\002eld)208 3170 y(without)28 b(a)j(terminating)d(ne)n(wline)
g(character)m(,)j(a)f(ne)n(wline)f(w)o(ould)g(be)g(inserted)g(into)h
(the)f(returned)f(\002eld.)53 b(This)30 b(beha)n(vior)208
3270 y(caused)f(problems)g(when)h(reading)f(\002les)j(that)e(contained)
f(carriage)g(return)h(characters)f(within)h(\002elds,)k(so)d(the)f
(code)g(w)o(as)208 3369 y(changed)22 b(to)j(return)f(the)h(\002eld)g
(without)f(inserting)f(ne)n(wlines.)39 b(As)25 b(a)g(consequence,)f(if)
h(ne)n(wlines)f(embedded)f(within)h(\002elds)208 3469
y(are)c(important,)e(the)i(input)g(should)f(be)h(split)h(into)f(lines)g
(in)h(a)f(manner)f(that)h(preserv)o(es)f(the)i(ne)n(wline)e
(characters.)208 3602 y(\(Contrib)n(uted)f(by)i(Skip)g(Montanaro)e(and)
h(Andre)n(w)h(McNamara.\))125 3768 y Fd(\017)41 b Fk(The)21
b Fh(datetime)h Fk(class)h(in)f(the)h Fh(datetime)e Fk(module)g(no)n(w)
h(has)g(a)h Fh(strptime\()p Ff(string)p Fh(,)48 b Ff(format)q
Fh(\))22 b Fk(method)f(for)h(parsing)208 3867 y(date)31
b(strings,)j(contrib)n(uted)c(by)h(Josh)g(Spoerri.)58
b(It)32 b(uses)g(the)g(same)g(format)e(characters)h(as)h
Fh(time.strptime\(\))d Fk(and)208 3967 y Fh(time.strftime\(\))p
Fk(:)444 4191 y Fg(from)44 b(datetime)f(import)h(datetime)444
4374 y(ts)g(=)h(datetime.strptime\('10:13:15)40 b(2006-03-07',)1475
4465 y('\045H:\045M:\045S)j(\045Y-\045m-\045d'\))125
4771 y Fd(\017)e Fk(The)15 b Fh(SequenceMatcher.get_matching_blocks)o
(\(\))10 b Fk(method)15 b(in)h(the)f Fh(difflib)g Fk(module)g(no)n(w)g
(guarantees)f(to)208 4870 y(return)j(a)h(minimal)g(list)h(of)f(blocks)g
(describing)e(matching)h(subsequences.)23 b(Pre)n(viously)-5
b(,)17 b(the)h(algorithm)e(w)o(ould)i(occasionally)208
4970 y(break)h(a)h(block)g(of)f(matching)g(elements)h(into)g(tw)o(o)h
(list)g(entries.)k(\(Enhancement)17 b(by)j(T)m(im)g(Peters.\))125
5136 y Fd(\017)41 b Fk(The)17 b Fh(doctest)g Fk(module)f(gained)g(a)i
Fh(SKIP)g Fk(option)e(that)i(k)o(eeps)f(an)h(e)o(xample)e(from)g(being)
h(e)o(x)o(ecuted)f(at)i(all.)25 b(This)18 b(is)g(intended)208
5236 y(for)h(code)h(snippets)g(that)g(are)g(usage)g(e)o(xamples)f
(intended)f(for)i(the)g(reader)f(and)h(aren')o(t)f(actually)g(test)j
(cases.)p 0 5549 3901 4 v 0 5649 a Fe(20)2188 b(13)83
b(Ne)n(w)-5 b(,)24 b(Impro)o(v)n(ed,)f(and)g(Remo)o(v)n(ed)g(Modules)p
eop end
%%Page: 21 21
TeXDict begin 21 20 bop 208 83 a Fk(An)28 b Ff(encoding)e
Fk(parameter)h(w)o(as)i(added)e(to)h(the)g Fh(testfile\(\))f
Fk(function)f(and)i(the)g Fh(DocFileSuite)f Fk(class)i(to)f(specify)208
183 y(the)h(\002le')-5 b(s)31 b(encoding.)52 b(This)30
b(mak)o(es)g(it)h(easier)f(to)g(use)g(non-ASCII)e(characters)h(in)h
(tests)h(contained)d(within)i(a)g(docstring.)208 282
y(\(Contrib)n(uted)18 b(by)i(Bjorn)g(T)m(illenius.\))125
448 y Fd(\017)41 b Fk(The)19 b Fh(email)h Fk(package)f(has)h(been)g
(updated)e(to)j(v)o(ersion)e(4.0.)24 b(\(Contrib)n(uted)18
b(by)i(Barry)g(W)-7 b(arsa)o(w)i(.\))125 614 y Fd(\017)41
b Fk(The)15 b Fh(fileinput)h Fk(module)e(w)o(as)j(made)f(more)f(\003e)o
(xible.)23 b(Unicode)16 b(\002lenames)g(are)g(no)n(w)f(supported,)g
(and)h(a)g Ff(mode)g Fk(parameter)208 714 y(that)22 b(def)o(aults)f(to)
i Fh("r")f Fk(w)o(as)h(added)e(to)h(the)g Fh(input\(\))g
Fk(function)e(to)i(allo)n(w)g(opening)f(\002les)i(in)f(binary)f(or)h
(uni)n(v)o(ersal-ne)n(wline)208 814 y(mode.)38 b(Another)23
b(ne)n(w)i(parameter)m(,)f Ff(openhook)q Fk(,)g(lets)i(you)e(use)h(a)g
(function)f(other)g(than)g Fh(open\(\))h Fk(to)g(open)f(the)h(input)f
(\002les.)208 913 y(Once)c(you')l(re)g(iterating)g(o)o(v)o(er)g(the)h
(set)h(of)f(\002les,)h(the)f Fh(FileInput)f Fk(object')-5
b(s)21 b(ne)n(w)g Fh(fileno\(\))g Fk(returns)f(the)h(\002le)h
(descriptor)208 1013 y(for)d(the)h(currently)f(opened)f(\002le.)26
b(\(Contrib)n(uted)18 b(by)i(Geor)o(g)f(Brandl.\))125
1179 y Fd(\017)41 b Fk(In)22 b(the)i Fh(gc)f Fk(module,)f(the)h(ne)n(w)
g Fh(get_count\(\))f Fk(function)f(returns)h(a)i(3-tuple)e(containing)f
(the)i(current)f(collection)g(counts)208 1279 y(for)d(the)g(three)g(GC)
i(generations.)i(This)d(is)g(accounting)e(information)f(for)i(the)h
(garbage)d(collector;)i(when)g(these)h(counts)f(reach)208
1378 y(a)26 b(speci\002ed)f(threshold,)g(a)h(garbage)d(collection)i
(sweep)g(will)i(be)e(made.)40 b(The)26 b(e)o(xisting)e
Fh(gc.collect\(\))g Fk(function)g(no)n(w)208 1478 y(tak)o(es)18
b(an)g(optional)e Ff(g)o(ener)o(ation)g Fk(ar)o(gument)g(of)h(0,)h(1,)h
(or)e(2)h(to)g(specify)f(which)h(generation)d(to)j(collect.)24
b(\(Contrib)n(uted)17 b(by)g(Barry)208 1577 y(W)-7 b(arsa)o(w)i(.\))125
1743 y Fd(\017)41 b Fk(The)15 b Fh(nsmallest\(\))f Fk(and)h
Fh(nlargest\(\))g Fk(functions)f(in)i(the)g Fh(heapq)f
Fk(module)g(no)n(w)g(support)f(a)i Fh(key)g Fk(k)o(e)o(yw)o(ord)e
(parameter)208 1843 y(similar)20 b(to)g(the)g(one)g(pro)o(vided)e(by)i
(the)g Fh(min\(\))p Fk(/)p Fh(max\(\))f Fk(functions)f(and)i(the)g
Fh(sort\(\))g Fk(methods.)k(F)o(or)c(e)o(xample:)444
2067 y Fg(>>>)44 b(import)g(heapq)444 2159 y(>>>)g(L)h(=)f(["short",)g
('medium',)f('longest',)g('longer)h(still'])444 2250
y(>>>)g(heapq.nsmallest\(2,)e(L\))89 b(#)45 b(Return)f(two)g(lowest)g
(elements,)f(lexicographically)444 2341 y(['longer)g(still',)h
('longest'])444 2433 y(>>>)g(heapq.nsmallest\(2,)e(L,)i(key=len\))134
b(#)44 b(Return)g(two)g(shortest)g(elements)444 2524
y(['short',)f('medium'])208 2796 y Fk(\(Contrib)n(uted)18
b(by)i(Raymond)e(Hettinger)-5 b(.\))125 2962 y Fd(\017)41
b Fk(The)16 b Fh(itertools.islice\(\))e Fk(function)i(no)n(w)g(accepts)
h Fh(None)g Fk(for)f(the)h(start)g(and)g(step)g(ar)o(guments.)22
b(This)17 b(mak)o(es)g(it)g(more)208 3062 y(compatible)h(with)j(the)f
(attrib)n(utes)g(of)g(slice)h(objects,)e(so)i(that)f(you)g(can)g(no)n
(w)f(write)i(the)f(follo)n(wing:)444 3286 y Fg(s)44 b(=)h(slice\(5\))
223 b(#)45 b(Create)e(slice)h(object)444 3378 y
(itertools.islice\(iterable,)c(s.start,)k(s.stop,)f(s.step\))208
3650 y Fk(\(Contrib)n(uted)18 b(by)i(Raymond)e(Hettinger)-5
b(.\))125 3816 y Fd(\017)41 b Fk(The)35 b Fh(format\(\))f
Fk(function)g(in)i(the)g Fh(locale)f Fk(module)f(has)i(been)f
(modi\002ed)f(and)h(tw)o(o)h(ne)n(w)f(functions)g(were)g(added,)208
3916 y Fh(format_string\(\))18 b Fk(and)h Fh(currency\(\))p
Fk(.)208 4048 y(The)31 b Fh(format\(\))g Fk(function')-5
b(s)30 b Ff(val)i Fk(parameter)e(could)g(pre)n(viously)g(be)i(a)g
(string)f(as)h(long)f(as)i(no)e(more)g(than)g(one)g(\045char)208
4148 y(speci\002er)15 b(appeared;)h(no)n(w)f(the)h(parameter)f(must)h
(be)g(e)o(xactly)f(one)g(\045char)g(speci\002er)h(with)g(no)g
(surrounding)d(te)o(xt.)23 b(An)16 b(optional)208 4248
y Ff(monetary)f Fk(parameter)g(w)o(as)i(also)g(added)e(which,)i(if)f
Fh(True)p Fk(,)h(will)g(use)g(the)f(locale')-5 b(s)17
b(rules)g(for)e(formatting)g(currenc)o(y)f(in)j(placing)208
4347 y(a)j(separator)f(between)h(groups)e(of)i(three)g(digits.)208
4480 y(T)-7 b(o)26 b(format)e(strings)i(with)g(multiple)f(\045char)h
(speci\002ers,)h(use)f(the)g(ne)n(w)f Fh(format_string\(\))f
Fk(function)g(that)i(w)o(orks)f(lik)o(e)208 4580 y Fh(format\(\))19
b Fk(b)n(ut)h(also)h(supports)e(mixing)g(\045char)g(speci\002ers)i
(with)f(arbitrary)f(te)o(xt.)208 4713 y(A)h(ne)n(w)g
Fh(currency\(\))f Fk(function)g(w)o(as)i(also)f(added)f(that)h(formats)
g(a)g(number)f(according)f(to)i(the)g(current)f(locale')-5
b(s)21 b(settings.)208 4845 y(\(Contrib)n(uted)d(by)i(Geor)o(g)e
(Brandl.\))125 5012 y Fd(\017)41 b Fk(The)25 b Fh(mailbox)g
Fk(module)g(underwent)e(a)k(massi)n(v)o(e)e(re)n(write)h(to)f(add)h
(the)g(capability)e(to)i(modify)f(mailbox)o(es)f(in)i(addition)e(to)208
5111 y(reading)18 b(them.)25 b(A)20 b(ne)n(w)g(set)g(of)g(classes)h
(that)f(include)f Fh(mbox)p Fk(,)h Fh(MH)p Fk(,)g(and)f
Fh(Maildir)g Fk(are)h(used)g(to)g(read)f(mailbox)o(es,)g(and)g(ha)n(v)o
(e)208 5211 y(an)i Fh(add\()p Ff(messa)o(g)o(e)p Fh(\))f
Fk(method)g(to)h(add)g(messages,)g Fh(remove\()p Ff(k)o(e)n(y)p
Fh(\))f Fk(to)h(remo)o(v)o(e)e(messages,)j(and)e Fh(lock\(\))p
Fk(/)p Fh(unlock\(\))f Fk(to)208 5310 y(lock/unlock)e(the)k(mailbox.)i
(The)d(follo)n(wing)f(e)o(xample)f(con)m(v)o(erts)h(a)h(maildir)n
(-format)e(mailbox)h(into)h(an)g(mbox-format)d(one:)p
0 5549 3901 4 v 3808 5649 a Fe(21)p eop end
%%Page: 22 22
TeXDict begin 22 21 bop 444 174 a Fg(import)44 b(mailbox)444
357 y(#)g('factory=None')f(uses)h(email.Message.Message)d(as)k(the)f
(class)g(representing)444 448 y(#)g(individual)g(messages.)444
540 y(src)g(=)h(mailbox.Maildir\('maildir',)40 b(factory=None\))444
631 y(dest)k(=)h(mailbox.mbox\('/tmp/mbox'\))444 814
y(for)f(msg)g(in)h(src:)623 905 y(dest.add\(msg\))208
1177 y Fk(\(Contrib)n(uted)18 b(by)i(Gre)o(gory)e(K.)i(Johnson.)k
(Funding)19 b(w)o(as)i(pro)o(vided)c(by)j(Google')-5
b(s)20 b(2005)e(Summer)h(of)h(Code.\))125 1343 y Fd(\017)41
b Fk(Ne)n(w)20 b(module:)j(the)d Fh(msilib)f Fk(module)g(allo)n(ws)h
(creating)f(Microsoft)f(Installer)i(`)p Fj(.msi)p Fk(')g(\002les)g(and)
g(CAB)h(\002les.)k(Some)20 b(support)208 1443 y(for)f(reading)g(the)h
(`)p Fj(.msi)p Fk(')g(database)g(is)h(also)f(included.)k(\(Contrib)n
(uted)18 b(by)i(Martin)g(v)n(on)f(L)7 b(\250)-35 b(owis.\))125
1609 y Fd(\017)41 b Fk(The)19 b Fh(nis)g Fk(module)g(no)n(w)g(supports)
f(accessing)h(domains)g(other)g(than)g(the)g(system)h(def)o(ault)f
(domain)f(by)h(supplying)f(a)i Ff(domain)208 1709 y Fk(ar)o(gument)d
(to)k(the)f Fh(nis.match\(\))f Fk(and)g Fh(nis.maps\(\))g
Fk(functions.)24 b(\(Contrib)n(uted)18 b(by)i(Ben)g(Bell.\))125
1875 y Fd(\017)41 b Fk(The)25 b Fh(operator)g Fk(module')-5
b(s)25 b Fh(itemgetter\(\))g Fk(and)g Fh(attrgetter\(\))f
Fk(functions)h(no)n(w)g(support)g(multiple)g(\002elds.)43
b(A)208 1974 y(call)32 b(such)f(as)h Fh(operator.attrgetter\('a',)46
b('b'\))31 b Fk(will)h(return)f(a)h(function)e(that)h(retrie)n(v)o(es)g
(the)g Fh(a)h Fk(and)f Fh(b)h Fk(at-)208 2074 y(trib)n(utes.)c
(Combining)20 b(this)i(ne)n(w)f(feature)f(with)i(the)f
Fh(sort\(\))g Fk(method')-5 b(s)20 b Fh(key)i Fk(parameter)d(lets)k
(you)d(easily)i(sort)f(lists)i(using)208 2174 y(multiple)c(\002elds.)25
b(\(Contrib)n(uted)19 b(by)h(Raymond)e(Hettinger)-5 b(.\))125
2340 y Fd(\017)41 b Fk(The)21 b Fh(optparse)g Fk(module)g(w)o(as)h
(updated)f(to)h(v)o(ersion)e(1.5.1)h(of)g(the)h(Optik)g(library)-5
b(.)28 b(The)22 b Fh(OptionParser)e Fk(class)j(gained)208
2439 y(an)f Fh(epilog)h Fk(attrib)n(ute,)g(a)g(string)g(that)g(will)h
(be)e(printed)g(after)h(the)g(help)f(message,)h(and)g(a)g
Fh(destroy\(\))f Fk(method)g(to)h(break)208 2539 y(reference)18
b(c)o(ycles)i(created)f(by)h(the)g(object.)25 b(\(Contrib)n(uted)18
b(by)i(Gre)o(g)g(W)-7 b(ard.\))125 2705 y Fd(\017)41
b Fk(The)17 b Fh(os)i Fk(module)d(underwent)g(se)n(v)o(eral)i(changes.)
23 b(The)18 b Fh(stat_float_times)e Fk(v)n(ariable)h(no)n(w)g(def)o
(aults)h(to)g(true,)g(meaning)208 2805 y(that)k Fh(os.stat\(\))f
Fk(will)j(no)n(w)e(return)f(time)h(v)n(alues)h(as)g(\003oats.)32
b(\(This)22 b(doesn')o(t)f(necessarily)h(mean)g(that)g
Fh(os.stat\(\))g Fk(will)208 2904 y(return)d(times)h(that)h(are)f
(precise)g(to)g(fractions)f(of)h(a)h(second;)e(not)h(all)h(systems)f
(support)f(such)h(precision.\))208 3037 y(Constants)15
b(named)g Fh(os.SEEK_SET)p Fk(,)f Fh(os.SEEK_CUR)p Fk(,)g(and)i
Fh(os.SEEK_END)e Fk(ha)n(v)o(e)h(been)g(added;)h(these)g(are)g(the)g
(param-)208 3137 y(eters)k(to)g(the)h Fh(os.lseek\(\))d
Fk(function.)24 b(T)-7 b(w)o(o)20 b(ne)n(w)g(constants)g(for)f(locking)
g(are)h Fh(os.O_SHLOCK)f Fk(and)h Fh(os.O_EXLOCK)p Fk(.)208
3270 y(T)-7 b(w)o(o)25 b(ne)n(w)f(functions,)g Fh(wait3\(\))h
Fk(and)f Fh(wait4\(\))p Fk(,)h(were)f(added.)38 b(The)o(y')l(re)23
b(similar)i(the)f Fh(waitpid\(\))g Fk(function)f(which)208
3369 y(w)o(aits)37 b(for)e(a)i(child)e(process)h(to)g(e)o(xit)g(and)f
(returns)h(a)g(tuple)g(of)f(the)i(process)e(ID)h(and)g(its)h(e)o(xit)f
(status,)k(b)n(ut)c Fh(wait3\(\))208 3469 y Fk(and)30
b Fh(wait4\(\))f Fk(return)h(additional)f(information.)54
b Fh(wait3\(\))29 b Fk(doesn')o(t)h(tak)o(e)g(a)h(process)f(ID)h(as)g
(input,)h(so)f(it)h(w)o(aits)f(for)208 3568 y(an)o(y)j(child)h(process)
f(to)h(e)o(xit)g(and)g(returns)f(a)i(3-tuple)e(of)g Ff(pr)l(ocess-id)r
Fk(,)39 b Ff(e)n(xit-status)p Fk(,)g Ff(r)m(esour)m(ce-usa)o(g)o(e)33
b Fk(as)j(returned)e(from)208 3668 y(the)e Fh(resource.getrusage\(\))d
Fk(function.)59 b Fh(wait4\()p Ff(pid)r Fh(\))31 b Fk(does)h(tak)o(e)g
(a)h(process)f(ID.)g(\(Contrib)n(uted)e(by)i(Chad)g(J.)208
3768 y(Schroeder)-5 b(.\))208 3901 y(On)20 b(FreeBSD,)g(the)g
Fh(os.stat\(\))f Fk(function)g(no)n(w)g(returns)h(times)g(with)h
(nanosecond)c(resolution,)i(and)h(the)g(returned)e(object)208
4000 y(no)n(w)h(has)h Fh(st_gen)f Fk(and)h Fh(st_birthtime)p
Fk(.)j(The)c Fh(st_flags)g Fk(member)g(is)i(also)f(a)n(v)n(ailable,)f
(if)h(the)g(platform)e(supports)h(it.)208 4100 y(\(Contrib)n(uted)f(by)
i(Antti)g(Louk)o(o)f(and)h(Die)o(go)f(Petten)7 b(\036)-35
b(o.\))125 4266 y Fd(\017)41 b Fk(The)22 b(Python)g(deb)n(ugger)e(pro)o
(vided)g(by)j(the)f Fh(pdb)h Fk(module)e(can)i(no)n(w)f(store)h(lists)h
(of)e(commands)f(to)i(e)o(x)o(ecute)f(when)g(a)h(break-)208
4365 y(point)f(is)i(reached)e(and)h(e)o(x)o(ecution)e(stops.)35
b(Once)23 b(breakpoint)e(#1)h(has)i(been)e(created,)i(enter)e(`)p
Fh(commands)48 b(1)p Fk(')24 b(and)e(enter)h(a)208 4465
y(series)d(of)f(commands)f(to)i(be)g(e)o(x)o(ecuted,)d(\002nishing)i
(the)h(list)h(with)f(`)p Fh(end)p Fk('.)k(The)19 b(command)f(list)i
(can)g(include)e(commands)g(that)208 4565 y(resume)h(e)o(x)o(ecution,)f
(such)i(as)h(`)p Fh(continue)p Fk(')d(or)i(`)p Fh(next)p
Fk('.)k(\(Contrib)n(uted)19 b(by)g(Gr)5 b(\264)-33 b(egoire)19
b(Dooms.\))125 4731 y Fd(\017)41 b Fk(The)30 b Fh(pickle)g
Fk(and)g Fh(cPickle)f Fk(modules)h(no)g(longer)f(accept)h(a)h(return)e
(v)n(alue)h(of)g Fh(None)g Fk(from)g(the)g Fh(__reduce__\(\))208
4830 y Fk(method;)e(the)f(method)e(must)h(return)g(a)h(tuple)f(of)g(ar)
o(guments)f(instead.)43 b(The)27 b(ability)f(to)h(return)e
Fh(None)h Fk(w)o(as)i(deprecated)c(in)208 4930 y(Python)19
b(2.4,)g(so)h(this)h(completes)f(the)g(remo)o(v)n(al)e(of)i(the)g
(feature.)125 5096 y Fd(\017)41 b Fk(The)19 b Fh(pkgutil)h
Fk(module,)e(containing)g(v)n(arious)h(utility)h(functions)f(for)g
(\002nding)g(packages,)g(w)o(as)i(enhanced)d(to)i(support)f(PEP)208
5196 y(302')-5 b(s)22 b(import)f(hooks)h(and)g(no)n(w)g(also)h(w)o
(orks)f(for)g(packages)f(stored)h(in)h(ZIP-format)d(archi)n(v)o(es.)31
b(\(Contrib)n(uted)21 b(by)h(Phillip)h(J.)208 5295 y(Eby)-5
b(.\))p 0 5549 3901 4 v 0 5649 a Fe(22)2188 b(13)83 b(Ne)n(w)-5
b(,)24 b(Impro)o(v)n(ed,)f(and)g(Remo)o(v)n(ed)g(Modules)p
eop end
%%Page: 23 23
TeXDict begin 23 22 bop 125 83 a Fd(\017)41 b Fk(The)22
b(p)o(ybench)f(benchmark)g(suite)i(by)g(Marc-Andr)5 b(\264)-33
b(e)20 b(Lemb)n(ur)o(g)h(is)j(no)n(w)f(included)e(in)i(the)g(`)p
Fj(T)-9 b(ools/p)n(ybench)p Fk(')20 b(directory)-5 b(.)31
b(The)208 183 y(p)o(ybench)d(suite)j(is)g(an)f(impro)o(v)o(ement)d(on)j
(the)g(commonly)e(used)j(`)p Fj(p)n(ystone)o(.p)n(y)p
Fk(')c(program)i(because)g(p)o(ybench)g(pro)o(vides)f(a)208
282 y(more)18 b(detailed)h(measurement)e(of)i(the)g(interpreter')-5
b(s)18 b(speed.)25 b(It)19 b(times)h(particular)e(operations)g(such)h
(as)g(function)f(calls,)i(tuple)208 382 y(slicing,)f(method)f(lookups,)
f(and)i(numeric)f(operations,)f(instead)i(of)g(performing)e(man)o(y)h
(dif)n(ferent)f(operations)h(and)h(reducing)208 482 y(the)h(result)g
(to)g(a)h(single)f(number)e(as)j(`)p Fj(p)n(ystone)o(.p)n(y)p
Fk(')d(does.)125 648 y Fd(\017)41 b Fk(The)19 b Fh(pyexpat)h
Fk(module)f(no)n(w)g(uses)i(v)o(ersion)e(2.0)g(of)h(the)h(Expat)e
(parser)-5 b(.)25 b(\(Contrib)n(uted)18 b(by)i(T)m(rent)g(Mick.\))125
814 y Fd(\017)41 b Fk(The)22 b Fh(Queue)f Fk(class)j(pro)o(vided)19
b(by)j(the)h Fh(Queue)f Fk(module)f(gained)f(tw)o(o)j(ne)n(w)f
(methods.)30 b Fh(join\(\))22 b Fk(blocks)g(until)g(all)h(items)f(in)
208 913 y(the)h(queue)f(ha)n(v)o(e)g(been)h(retrie)n(v)o(ed)e(and)i
(all)h(processing)e(w)o(ork)g(on)h(the)g(items)h(ha)n(v)o(e)f(been)f
(completed.)33 b(W)-7 b(ork)o(er)23 b(threads)f(call)208
1013 y(the)e(other)g(ne)n(w)g(method,)f Fh(task_done\(\))p
Fk(,)g(to)i(signal)g(that)f(processing)g(for)g(an)g(item)h(has)g(been)f
(completed.)k(\(Contrib)n(uted)208 1112 y(by)19 b(Raymond)g(Hettinger)
-5 b(.\))125 1279 y Fd(\017)41 b Fk(The)25 b(old)g Fh(regex)g
Fk(and)g Fh(regsub)g Fk(modules,)h(which)f(ha)n(v)o(e)g(been)g
(deprecated)f(e)n(v)o(er)h(since)g(Python)g(2.0,)h(ha)n(v)o(e)f
(\002nally)g(been)208 1378 y(deleted.)f(Other)c(deleted)f(modules:)24
b Fh(statcache)p Fk(,)19 b Fh(tzparse)p Fk(,)g Fh(whrandom)p
Fk(.)125 1544 y Fd(\017)41 b Fk(Also)25 b(deleted:)36
b(the)25 b(`)p Fj(lib-old)p Fk(')e(directory)-5 b(,)24
b(which)h(includes)g(ancient)g(modules)f(such)h(as)h
Fh(dircmp)f Fk(and)g Fh(ni)p Fk(,)i(w)o(as)f(remo)o(v)o(ed.)208
1644 y(`)p Fj(lib-old)p Fk(')12 b(w)o(asn')o(t)j(on)g(the)h(def)o(ault)
f Fh(sys.path)p Fk(,)g(so)h(unless)g(your)e(programs)g(e)o(xplicitly)g
(added)h(the)g(directory)f(to)i Fh(sys.path)p Fk(,)208
1743 y(this)k(remo)o(v)n(al)f(shouldn')o(t)f(af)n(fect)h(your)g(code.)
125 1910 y Fd(\017)41 b Fk(The)24 b Fh(rlcompleter)f
Fk(module)h(is)h(no)g(longer)e(dependent)g(on)h(importing)f(the)i
Fh(readline)f Fk(module)f(and)h(therefore)f(no)n(w)208
2009 y(w)o(orks)c(on)h(non-)r(U)t Fb(N)t(I)t(X)i Fk(platforms.)h(\(P)o
(atch)d(from)f(Robert)h(Kiendl.\))125 2175 y Fd(\017)41
b Fk(The)21 b Fh(SimpleXMLRPCServer)d Fk(and)j Fh(DocXMLRPCServer)e
Fk(classes)k(no)n(w)e(ha)n(v)o(e)g(a)h Fh(rpc_paths)e
Fk(attrib)n(ute)h(that)g(con-)208 2275 y(strains)26 b(XML-RPC)g
(operations)e(to)i(a)h(limited)e(set)i(of)f(URL)g(paths;)j(the)d(def)o
(ault)f(is)i(to)f(allo)n(w)f(only)g Fh('/')h Fk(and)g
Fh('/RPC2')p Fk(.)208 2374 y(Setting)20 b Fh(rpc_paths)f
Fk(to)h Fh(None)g Fk(or)g(an)g(empty)f(tuple)h(disables)g(this)h(path)f
(checking.)125 2540 y Fd(\017)41 b Fk(The)23 b Fh(socket)g
Fk(module)g(no)n(w)g(supports)g Fh(AF_NETLINK)f Fk(sock)o(ets)i(on)f
(Linux,)h(thanks)f(to)h(a)g(patch)f(from)g(Philippe)g(Biondi.)208
2640 y(Netlink)g(sock)o(ets)i(are)f(a)g(Linux-speci\002c)e(mechanism)h
(for)h(communications)d(between)i(a)i(user)n(-space)e(process)h(and)f
(k)o(ernel)208 2740 y(code;)h(an)f(introductory)e(article)i(about)g
(them)g(is)h(at)g Fj(
http://www)l(.lin)o(uxjour)r(na)o(l.co)o(m/ar)s
(ti)o(cle/7)o(35)o(6)-6 b Fk(.)35 b(In)23 b(Python)f(code,)h(netlink)
208 2839 y(addresses)c(are)i(represented)d(as)j(a)f(tuple)g(of)g(2)g
(inte)o(gers,)g Fh(\()p Ff(pid)r Fh(,)48 b Ff(gr)l(oup)p
2320 2839 25 4 v 29 w(mask)q Fh(\))p Fk(.)208 2972 y(T)-7
b(w)o(o)18 b(ne)n(w)g(methods)g(on)g(sock)o(et)g(objects,)g
Fh(recv_into\()p Ff(b)n(uf)o(fer)r Fh(\))e Fk(and)i Fh(recvfrom_into\()
p Ff(b)n(uf)o(fer)r Fh(\))p Fk(,)d(store)k(the)f(recei)n(v)o(ed)208
3072 y(data)j(in)i(an)f(object)f(that)h(supports)f(the)h(b)n(uf)n(fer)f
(protocol)g(instead)g(of)h(returning)e(the)i(data)g(as)h(a)f(string.)31
b(This)22 b(means)g(you)f(can)208 3171 y(put)e(the)i(data)f(directly)f
(into)h(an)g(array)f(or)h(a)h(memory-mapped)16 b(\002le.)208
3304 y(Sock)o(et)j(objects)g(also)h(gained)e Fh(getfamily\(\))p
Fk(,)g Fh(gettype\(\))p Fk(,)h(and)g Fh(getproto\(\))f
Fk(accessor)i(methods)e(to)i(retrie)n(v)o(e)f(the)208
3404 y(f)o(amily)-5 b(,)19 b(type,)g(and)h(protocol)e(v)n(alues)i(for)g
(the)g(sock)o(et.)125 3570 y Fd(\017)41 b Fk(Ne)n(w)18
b(module:)23 b(the)18 b Fh(spwd)g Fk(module)e(pro)o(vides)h(functions)f
(for)i(accessing)f(the)h(shado)n(w)g(passw)o(ord)f(database)g(on)h
(systems)g(that)208 3670 y(support)g(shado)n(w)i(passw)o(ords.)125
3836 y Fd(\017)41 b Fk(The)e Fh(struct)g Fk(is)i(no)n(w)e(f)o(aster)h
(because)f(it)h(compiles)f(format)g(strings)g(into)h
Fh(Struct)f Fk(objects)g(with)h Fh(pack\(\))f Fk(and)208
3935 y Fh(unpack\(\))25 b Fk(methods.)44 b(This)27 b(is)h(similar)f(to)
g(ho)n(w)g(the)f Fh(re)i Fk(module)d(lets)j(you)e(create)g(compiled)g
(re)o(gular)f(e)o(xpression)g(ob-)208 4035 y(jects.)f(Y)-9
b(ou)18 b(can)f(still)i(use)f(the)g(module-le)n(v)o(el)d
Fh(pack\(\))i Fk(and)h Fh(unpack\(\))e Fk(functions;)i(the)o(y')o(ll)f
(create)g Fh(Struct)h Fk(objects)f(and)208 4134 y(cache)i(them.)25
b(Or)20 b(you)f(can)h(use)h Fh(Struct)e Fk(instances)i(directly:)444
4359 y Fg(s)44 b(=)h(struct.Struct\('ih3s'\))444 4541
y(data)f(=)h(s.pack\(1972,)d(187,)j('abc'\))444 4633
y(year,)f(number,)f(name)i(=)f(s.unpack\(data\))208 4905
y Fk(Y)-9 b(ou)19 b(can)i(also)f(pack)g(and)g(unpack)f(data)h(to)h(and)
f(from)f(b)n(uf)n(fer)g(objects)h(directly)g(using)g(the)g
Fh(pack_into\()p Ff(b)n(uf)o(fer)r Fh(,)47 b Ff(of)o(fset)q
Fh(,)208 5005 y Ff(v1)p Fh(,)i Ff(v2)p Fh(,)g(...\))27
b Fk(and)20 b Fh(unpack_from\()p Ff(b)n(uf)o(fer)r Fh(,)47
b Ff(of)o(fset)q Fh(\))21 b Fk(methods.)27 b(This)21
b(lets)h(you)e(store)h(data)g(directly)f(into)h(an)f(array)208
5105 y(or)f(a)i(memory-mapped)16 b(\002le.)208 5237 y(\()p
Fh(Struct)25 b Fk(objects)h(were)g(implemented)f(by)h(Bob)g(Ippolito)f
(at)i(the)f(NeedF)o(orSpeed)e(sprint.)43 b(Support)25
b(for)h(b)n(uf)n(fer)f(objects)208 5337 y(w)o(as)c(added)e(by)g(Martin)
h(Blais,)h(also)g(at)g(the)f(NeedF)o(orSpeed)e(sprint.\))p
0 5549 3901 4 v 3808 5649 a Fe(23)p eop end
%%Page: 24 24
TeXDict begin 24 23 bop 125 83 a Fd(\017)41 b Fk(The)35
b(Python)f(de)n(v)o(elopers)g(switched)h(from)g(CVS)h(to)g(Sub)o(v)o
(ersion)d(during)h(the)i(2.5)f(de)n(v)o(elopment)d(process.)71
b(Informa-)208 183 y(tion)26 b(about)g(the)h(e)o(xact)f(b)n(uild)g(v)o
(ersion)g(is)i(a)n(v)n(ailable)e(as)i(the)e Fh(sys.subversion)f
Fk(v)n(ariable,)i(a)g(3-tuple)f(of)h Fh(\()p Ff(interpr)m(eter)n(-)208
282 y(name)p Fh(,)48 b Ff(br)o(anc)o(h-name)p Fh(,)e
Ff(r)m(e)o(vision-r)o(ang)o(e)p Fh(\))p Fk(.)k(F)o(or)29
b(e)o(xample,)h(at)g(the)g(time)f(of)g(writing)g(my)g(cop)o(y)g(of)g
(2.5)f(w)o(as)j(reporting)208 382 y Fh(\('CPython',)47
b('trunk',)i('45313:45315'\))p Fk(.)208 515 y(This)19
b(information)d(is)k(also)f(a)n(v)n(ailable)f(to)h(C)h(e)o(xtensions)e
(via)h(the)f Fh(Py_GetBuildInfo\(\))f Fk(function)g(that)i(returns)f(a)
h(string)208 614 y(of)28 b(b)n(uild)g(information)e(lik)o(e)j(this:)43
b Fh("trunk:45355:45356M,)j(Apr)j(13)g(2006,)g(07:42:19")p
Fk(.)g(\(Contrib)n(uted)208 714 y(by)19 b(Barry)h(W)-7
b(arsa)o(w)i(.\))125 880 y Fd(\017)41 b Fk(Another)21
b(ne)n(w)h(function,)f Fh(sys._current_frames\(\))p Fk(,)f(returns)h
(the)i(current)e(stack)i(frames)f(for)g(all)h(running)d(threads)208
980 y(as)j(a)g(dictionary)e(mapping)g(thread)h(identi\002ers)h(to)g
(the)g(topmost)f(stack)h(frame)f(currently)f(acti)n(v)o(e)h(in)h(that)g
(thread)f(at)i(the)e(time)208 1079 y(the)e(function)e(is)j(called.)k
(\(Contrib)n(uted)19 b(by)g(T)m(im)i(Peters.\))125 1245
y Fd(\017)41 b Fk(The)22 b Fh(TarFile)f Fk(class)j(in)e(the)g
Fh(tarfile)g Fk(module)f(no)n(w)h(has)g(an)h Fh(extractall\(\))d
Fk(method)h(that)i(e)o(xtracts)f(all)h(members)208 1345
y(from)17 b(the)h(archi)n(v)o(e)e(into)i(the)g(current)f(w)o(orking)f
(directory)-5 b(.)22 b(It')-5 b(s)19 b(also)f(possible)g(to)g(set)h(a)g
(dif)n(ferent)d(directory)g(as)j(the)f(e)o(xtraction)208
1445 y(tar)o(get,)h(and)g(to)i(unpack)d(only)h(a)i(subset)f(of)g(the)h
(archi)n(v)o(e')-5 b(s)19 b(members.)208 1577 y(The)26
b(compression)f(used)h(for)h(a)g(tar\002le)g(opened)e(in)i(stream)f
(mode)g(can)h(no)n(w)f(be)h(autodetected)d(using)j(the)f(mode)g
Fh('r|)3780 1592 y(*)3830 1577 y(')p Fk(.)208 1677 y(\(Contrib)n(uted)
18 b(by)i(Lars)g(Gust)5 b(\250)-33 b(abel.\))125 1843
y Fd(\017)41 b Fk(The)24 b Fh(threading)g Fk(module)f(no)n(w)h(lets)i
(you)e(set)h(the)g(stack)g(size)g(used)g(when)f(ne)n(w)g(threads)g(are)
h(created.)38 b(The)24 b Fh(stack_-)208 1943 y(size\()p
Fa([)p Ff(size)12 b Fa(])p Fh(\))23 b Fk(function)f(returns)g(the)i
(currently)e(con\002gured)f(stack)j(size,)h(and)e(supplying)f(the)i
(optional)e Ff(size)j Fk(parameter)208 2042 y(sets)e(a)f(ne)n(w)g(v)n
(alue.)29 b(Not)22 b(all)h(platforms)e(support)f(changing)g(the)i
(stack)g(size,)h(b)n(ut)f(W)m(indo)n(ws,)f(POSIX)i(threading,)d(and)h
(OS/2)208 2142 y(all)f(do.)25 b(\(Contrib)n(uted)18 b(by)i(Andre)n(w)f
(MacIntyre.\))125 2308 y Fd(\017)41 b Fk(The)21 b Fh(unicodedata)e
Fk(module)h(has)i(been)e(updated)g(to)i(use)f(v)o(ersion)f(4.1.0)g(of)h
(the)g(Unicode)g(character)f(database.)27 b(V)-9 b(ersion)208
2408 y(3.2.0)18 b(is)j(required)e(by)h(some)g(speci\002cations,)f(so)i
(it')-5 b(s)21 b(still)g(a)n(v)n(ailable)f(as)h Fh
(unicodedata.ucd_3_2_0)p Fk(.)125 2574 y Fd(\017)41 b
Fk(Ne)n(w)21 b(module:)26 b(the)21 b Fh(uuid)g Fk(module)f(generates)h
(uni)n(v)o(ersally)e(unique)h(identi\002ers)h(\(UUIDs\))g(according)e
(to)i(RFC)i(4122.)k(The)208 2673 y(RFC)18 b(de\002nes)f(se)n(v)o(eral)f
(dif)n(ferent)f(UUID)i(v)o(ersions)f(that)i(are)e(generated)g(from)g(a)
h(starting)g(string,)g(from)f(system)h(properties,)f(or)208
2773 y(purely)21 b(randomly)-5 b(.)31 b(This)23 b(module)e(contains)i
(a)g Fh(UUID)g Fk(class)h(and)e(functions)f(named)h Fh(uuid1\(\))p
Fk(,)h Fh(uuid3\(\))p Fk(,)g Fh(uuid4\(\))p Fk(,)208
2873 y(and)18 b Fh(uuid5\(\))g Fk(to)h(generate)e(dif)n(ferent)g(v)o
(ersions)h(of)g(UUID.)h(\(V)-9 b(ersion)18 b(2)g(UUIDs)h(are)g(not)g
(speci\002ed)f(in)h(RFC)h(4122)d(and)i(are)208 2972 y(not)g(supported)g
(by)g(this)i(module.\))444 3196 y Fg(>>>)44 b(import)g(uuid)444
3288 y(>>>)g(#)h(make)f(a)h(UUID)f(based)g(on)g(the)h(host)f(ID)g(and)h
(current)e(time)444 3379 y(>>>)h(uuid.uuid1\(\))444 3470
y(UUID\('a8098c1a-f86e-11da-bd1a-00112444)o(be1e'\))444
3653 y(>>>)g(#)h(make)f(a)h(UUID)f(using)g(an)g(MD5)h(hash)f(of)g(a)h
(namespace)e(UUID)h(and)h(a)f(name)444 3744 y(>>>)g
(uuid.uuid3\(uuid.NAMESPACE_DNS,)c('python.org'\))444
3836 y(UUID\('6fa459ea-ee8a-3ca4-894e-db77e160)o(355e'\))444
4018 y(>>>)k(#)h(make)f(a)h(random)e(UUID)444 4110 y(>>>)h
(uuid.uuid4\(\))444 4201 y(UUID\('16fd2706-8baf-433b-82eb-8c7fada8)o
(47da'\))444 4384 y(>>>)g(#)h(make)f(a)h(UUID)f(using)g(a)g(SHA-1)g
(hash)h(of)f(a)h(namespace)e(UUID)h(and)h(a)f(name)444
4475 y(>>>)g(uuid.uuid5\(uuid.NAMESPACE_DNS,)c('python.org'\))444
4566 y(UUID\('886313e1-3b8a-5372-9b90-0c9aee19)o(9e5d'\))208
4839 y Fk(\(Contrib)n(uted)18 b(by)i(Ka-Ping)f(Y)-8 b(ee.\))125
5005 y Fd(\017)41 b Fk(The)19 b Fh(weakref)g Fk(module')-5
b(s)19 b Fh(WeakKeyDictionary)e Fk(and)i Fh(WeakValueDictionary)e
Fk(types)j(gained)e(ne)n(w)i(methods)208 5104 y(for)h(iterating)h(o)o
(v)o(er)f(the)h(weak)g(references)f(contained)f(in)j(the)f(dictionary)
-5 b(.)29 b Fh(iterkeyrefs\(\))20 b Fk(and)i Fh(keyrefs\(\))f
Fk(meth-)208 5204 y(ods)28 b(were)h(added)f(to)h Fh(WeakKeyDictionary)p
Fk(,)f(and)g Fh(itervaluerefs\(\))f Fk(and)h Fh(valuerefs\(\))g
Fk(were)h(added)e(to)208 5304 y Fh(WeakValueDictionary)p
Fk(.)21 b(\(Contrib)n(uted)e(by)h(Fred)g(L.)g(Drak)o(e,)f(Jr)-5
b(.\))p 0 5549 3901 4 v 0 5649 a Fe(24)2188 b(13)83 b(Ne)n(w)-5
b(,)24 b(Impro)o(v)n(ed,)f(and)g(Remo)o(v)n(ed)g(Modules)p
eop end
%%Page: 25 25
TeXDict begin 25 24 bop 125 83 a Fd(\017)41 b Fk(The)21
b Fh(webbrowser)f Fk(module)h(recei)n(v)o(ed)f(a)i(number)e(of)h
(enhancements.)28 b(It')-5 b(s)22 b(no)n(w)f(usable)h(as)g(a)g(script)g
(with)g Fh(python)48 b(-m)208 183 y(webbrowser)p Fk(,)29
b(taking)g(a)g(URL)h(as)g(the)f(ar)o(gument;)i(there)e(are)g(a)g
(number)f(of)h(switches)g(to)g(control)f(the)i(beha)n(viour)d(\()p
Fi(-n)208 282 y Fk(for)22 b(a)h(ne)n(w)g(bro)n(wser)f(windo)n(w)-5
b(,)22 b Fi(-t)h Fk(for)g(a)g(ne)n(w)g(tab\).)33 b(Ne)n(w)23
b(module-le)n(v)o(el)e(functions,)h Fh(open_new\(\))f
Fk(and)i Fh(open_new_-)208 382 y(tab\(\))p Fk(,)16 b(were)h(added)e(to)
i(support)e(this.)24 b(The)16 b(module')-5 b(s)16 b Fh(open\(\))g
Fk(function)f(supports)g(an)i(additional)e(feature,)h(an)h
Ff(autor)o(aise)208 482 y Fk(parameter)h(that)j(signals)g(whether)e(to)
i(raise)g(the)f(open)f(windo)n(w)h(when)g(possible.)25
b(A)c(number)e(of)h(additional)f(bro)n(wsers)h(were)208
581 y(added)d(to)i(the)g(supported)e(list)j(such)f(as)g(Firefox,)f
(Opera,)g(K)m(onqueror)m(,)e(and)i(elinks.)25 b(\(Contrib)n(uted)17
b(by)h(Ole)o(g)h(Bro)o(ytmann)e(and)208 681 y(Geor)o(g)h(Brandl.\))125
847 y Fd(\017)41 b Fk(The)28 b Fh(xmlrpclib)f Fk(module)h(no)n(w)g
(supports)f(returning)g Fh(datetime)g Fk(objects)i(for)f(the)g(XML-RPC)
i(date)e(type.)50 b(Supply)208 946 y Fh(use_datetime=True)17
b Fk(to)k(the)f Fh(loads\(\))g Fk(function)f(or)h(the)g
Fh(Unmarshaller)f Fk(class)i(to)g(enable)f(this)h(feature.)j(\(Con-)208
1046 y(trib)n(uted)19 b(by)h(Skip)g(Montanaro.\))125
1212 y Fd(\017)41 b Fk(The)23 b Fh(zipfile)f Fk(module)h(no)n(w)f
(supports)h(the)g(ZIP64)g(v)o(ersion)f(of)h(the)h(format,)f(meaning)f
(that)h(a)h(.zip)f(archi)n(v)o(e)f(can)i(no)n(w)f(be)208
1312 y(lar)o(ger)18 b(than)i(4)g(GiB)i(and)d(can)h(contain)f(indi)n
(vidual)g(\002les)i(lar)o(ger)e(than)h(4)g(GiB.)h(\(Contrib)n(uted)d
(by)i(Ronald)f(Oussoren.\))125 1478 y Fd(\017)41 b Fk(The)19
b Fh(zlib)g Fk(module')-5 b(s)18 b Fh(Compress)h Fk(and)g
Fh(Decompress)f Fk(objects)h(no)n(w)g(support)f(a)i Fh(copy\(\))f
Fk(method)f(that)h(mak)o(es)h(a)f(cop)o(y)208 1577 y(of)28
b(the)g(object')-5 b(s)29 b(internal)f(state)h(and)f(returns)g(a)h(ne)n
(w)f Fh(Compress)g Fk(or)g Fh(Decompress)f Fk(object.)50
b(\(Contrib)n(uted)27 b(by)h(Chris)208 1677 y(AtLee.\))0
1962 y Fc(13.1)100 b(The)29 b(ctypes)e(pac)n(kage)0 2165
y Fk(The)j Fh(ctypes)g Fk(package,)i(written)e(by)g(Thomas)g(Heller)m
(,)j(has)d(been)g(added)g(to)g(the)h(standard)e(library)-5
b(.)55 b Fh(ctypes)30 b Fk(lets)h(you)f(call)0 2264 y(arbitrary)g
(functions)g(in)h(shared)g(libraries)g(or)g(DLLs.)59
b(Long-time)29 b(users)j(may)f(remember)e(the)i Fh(dl)h
Fk(module,)g(which)f(pro)o(vides)0 2364 y(functions)19
b(for)g(loading)g(shared)h(libraries)f(and)h(calling)g(functions)f(in)h
(them.)k(The)c Fh(ctypes)g Fk(package)f(is)i(much)e(f)o(ancier)-5
b(.)0 2511 y(T)e(o)23 b(load)g(a)g(shared)g(library)f(or)g(DLL,)h(you)f
(must)h(create)g(an)g(instance)g(of)f(the)i Fh(CDLL)e
Fk(class)i(and)f(pro)o(vide)e(the)i(name)f(or)h(path)g(of)g(the)0
2611 y(shared)d(library)g(or)g(DLL.)h(Once)f(that')-5
b(s)21 b(done,)f(you)g(can)g(call)i(arbitrary)d(functions)g(by)h
(accessing)h(them)f(as)i(attrib)n(utes)e(of)h(the)g Fh(CDLL)0
2710 y Fk(object.)236 2948 y Fg(import)44 b(ctypes)236
3131 y(libc)g(=)h(ctypes.CDLL\('libc.so.6'\))236 3222
y(result)f(=)h(libc.printf\("Line)d(of)i(output\\n"\))0
3509 y Fk(T)-7 b(ype)23 b(constructors)f(for)h(the)h(v)n(arious)e(C)j
(types)e(are)h(pro)o(vided:)29 b Fh(c_int)p Fk(,)24 b
Fh(c_float)p Fk(,)g Fh(c_double)p Fk(,)f Fh(c_char_p)g
Fk(\(equi)n(v)n(alent)e(to)0 3609 y Fh(char)249 3624
y(*)299 3609 y Fk(\),)e(and)f(so)h(forth.)k(Unlik)o(e)18
b(Python')-5 b(s)18 b(types,)g(the)h(C)g(v)o(ersions)f(are)g(all)h
(mutable;)f(you)g(can)g(assign)h(to)g(their)f Fh(value)g
Fk(attrib)n(ute)0 3708 y(to)f(change)e(the)i(wrapped)e(v)n(alue.)23
b(Python)16 b(inte)o(gers)g(and)g(strings)h(will)g(be)g(automatically)e
(con)m(v)o(erted)f(to)j(the)g(corresponding)c(C)18 b(types,)0
3808 y(b)n(ut)k(for)g(other)f(types)h(you)f(must)h(call)h(the)f
(correct)f(type)h(constructor)-5 b(.)29 b(\(And)22 b(I)g(mean)f
Ff(must)p Fk(;)j(getting)d(it)i(wrong)e(will)i(often)e(result)h(in)0
3907 y(the)e(interpreter)f(crashing)g(with)h(a)h(se)o(gmentation)d(f)o
(ault.\))0 4054 y(Y)-9 b(ou)19 b(shouldn')o(t)f(use)i
Fh(c_char_p)f Fk(with)h(a)h(Python)d(string)i(when)f(the)h(C)h
(function)d(will)j(be)f(modifying)e(the)h(memory)g(area,)g(because)0
4154 y(Python)d(strings)h(are)g(supposed)f(to)h(be)g(immutable;)g
(breaking)e(this)i(rule)g(will)h(cause)f(puzzling)e(b)n(ugs.)24
b(When)17 b(you)f(need)g(a)i(modi\002able)0 4254 y(memory)g(area,)i
(use)h Fh(create_string_buffer\(\))p Fk(:)236 4492 y
Fg(s)45 b(=)g("this)f(is)g(a)h(string")236 4583 y(buf)g(=)f
(ctypes.create_string_buffer\(s\))236 4674 y(libc.strfry\(buf\))0
4961 y Fk(C)26 b(functions)e(are)h(assumed)g(to)g(return)f(inte)o
(gers,)i(b)n(ut)f(you)f(can)h(set)h(the)g Fh(restype)e
Fk(attrib)n(ute)h(of)g(the)g(function)f(object)g(to)i(change)0
5061 y(this:)p 0 5549 3901 4 v 0 5649 a Fe(13.1)84 b(The)23
b(ctypes)f(pac)n(kage)2822 b(25)p eop end
%%Page: 26 26
TeXDict begin 26 25 bop 236 174 a Fg(>>>)45 b(libc.atof\('2.71828'\))
236 266 y(-1783957616)236 357 y(>>>)g(libc.atof.restype)d(=)i
(ctypes.c_double)236 448 y(>>>)h(libc.atof\('2.71828'\))236
540 y(2.71828)0 826 y Fh(ctypes)29 b Fk(also)g(pro)o(vides)e(a)j
(wrapper)d(for)i(Python')-5 b(s)28 b(C)i(API)g(as)f(the)g
Fh(ctypes.pythonapi)e Fk(object.)51 b(This)30 b(object)e(does)h
Ff(not)0 926 y Fk(release)i(the)g(global)g(interpreter)e(lock)i(before)
e(calling)i(a)h(function,)f(because)g(the)g(lock)g(must)g(be)g(held)g
(when)f(calling)h(into)g(the)0 1025 y(interpreter')-5
b(s)27 b(code.)50 b(There')-5 b(s)28 b(a)h Fh(py_object\(\))e
Fk(type)h(constructor)f(that)h(will)i(create)e(a)h Fh(PyObject)3208
1040 y(*)3287 1025 y Fk(pointer)-5 b(.)50 b(A)29 b(simple)0
1125 y(usage:)236 1363 y Fg(import)44 b(ctypes)236 1546
y(d)h(=)g({})236 1637 y(ctypes.pythonapi.PyObject_SetItem\(ctypes)o
(.py_ob)o(ject\(d)o(\),)685 1729 y(ctypes.py_object\("abc"\),)85
b(ctypes.py_object\(1\)\))236 1820 y(#)45 b(d)g(is)f(now)g({'abc',)g
(1}.)0 2106 y Fk(Don')o(t)19 b(for)o(get)f(to)j(use)f
Fh(py_object\(\))p Fk(;)f(if)h(it')-5 b(s)22 b(omitted)d(you)h(end)f
(up)h(with)g(a)h(se)o(gmentation)d(f)o(ault.)0 2253 y
Fh(ctypes)23 b Fk(has)i(been)e(around)f(for)h(a)i(while,)g(b)n(ut)f
(people)e(still)k(write)e(and)f(distrib)n(ution)g(hand-coded)e(e)o
(xtension)h(modules)h(because)0 2353 y(you)29 b(can')o(t)g(rely)h(on)g
Fh(ctypes)g Fk(being)f(present.)54 b(Perhaps)30 b(de)n(v)o(elopers)e
(will)j(be)o(gin)e(to)h(write)g(Python)f(wrappers)g(atop)h(a)h(library)
0 2452 y(accessed)20 b(through)e Fh(ctypes)i Fk(instead)g(of)g(e)o
(xtension)e(modules,)h(no)n(w)h(that)g Fh(ctypes)g Fk(is)h(included)e
(with)h(core)g(Python.)0 2599 y Fi(See)h(Also:)0 2746
y Fj(
http://starship)m(.p)n(ython.net)o(/cre)n(w/th)o(ell)o(er/)o
(ctypes/)208 2846 y Fk(The)e(ctypes)h(web)g(page,)g(with)g(a)h
(tutorial,)e(reference,)f(and)i(F)-6 b(A)h(Q.)0 2993
y Fj(../lib/module-ctypes)o(.html)208 3092 y Fk(The)19
b(documentation)f(for)h(the)h Fh(ctypes)g Fk(module.)0
3377 y Fc(13.2)100 b(The)29 b(ElementT)-12 b(ree)30 b(pac)n(kage)0
3580 y Fk(A)j(subset)f(of)g(Fredrik)g(Lundh')-5 b(s)31
b(ElementT)m(ree)g(library)g(for)h(processing)f(XML)h(has)h(been)e
(added)g(to)i(the)f(standard)g(library)f(as)0 3680 y
Fh(xml.etree)p Fk(.)23 b(The)c(a)n(v)n(ailable)g(modules)f(are)h
Fh(ElementTree)p Fk(,)e Fh(ElementPath)p Fk(,)h(and)h
Fh(ElementInclude)e Fk(from)h(Element-)0 3779 y(T)m(ree)i(1.2.6.)j(The)
d Fh(cElementTree)f Fk(accelerator)g(module)g(is)i(also)f(included.)0
3926 y(The)k(rest)i(of)e(this)i(section)e(will)i(pro)o(vide)d(a)i
(brief)f(o)o(v)o(ervie)n(w)f(of)h(using)h(ElementT)m(ree.)37
b(Full)25 b(documentation)d(for)i(ElementT)m(ree)g(is)0
4026 y(a)n(v)n(ailable)c(at)g Fj(
http://effbot.org/z)o(one/)o(ele)o
(men)o(t-in)o(de)m(x.htm)-6 b Fk(.)0 4173 y(ElementT)m(ree)21
b(represents)h(an)g(XML)h(document)d(as)j(a)g(tree)g(of)f(element)g
(nodes.)31 b(The)22 b(te)o(xt)h(content)e(of)h(the)h(document)d(is)k
(stored)e(as)0 4272 y(the)k Fh(.text)g Fk(and)f Fh(.tail)h
Fk(attrib)n(utes)g(of)g(\(This)g(is)h(one)e(of)h(the)g(major)f(dif)n
(ferences)g(between)g(ElementT)m(ree)g(and)g(the)h(Document)0
4372 y(Object)20 b(Model;)g(in)g(the)g(DOM)h(there)e(are)i(man)o(y)e
(dif)n(ferent)f(types)i(of)g(node,)f(including)f Fh(TextNode)p
Fk(.\))0 4519 y(The)k(most)f(commonly)f(used)i(parsing)f(function)f(is)
j Fh(parse\(\))p Fk(,)e(that)h(tak)o(es)g(either)g(a)g(string)g
(\(assumed)f(to)h(contain)e(a)j(\002lename\))e(or)0 4619
y(a)g(\002le-lik)o(e)f(object)f(and)h(returns)f(an)i
Fh(ElementTree)d Fk(instance:)p 0 5549 3901 4 v 0 5649
a Fe(26)2188 b(13)83 b(Ne)n(w)-5 b(,)24 b(Impro)o(v)n(ed,)f(and)g(Remo)
o(v)n(ed)g(Modules)p eop end
%%Page: 27 27
TeXDict begin 27 26 bop 236 174 a Fg(from)44 b(xml.etree)g(import)g
(ElementTree)f(as)h(ET)236 357 y(tree)g(=)h(ET.parse\('ex-1.xml'\))236
540 y(feed)f(=)h(urllib.urlopen\()685 631 y
('
http://planet.python.org/rss10.xml')o(\))236 722 y(tree)f(=)h
(ET.parse\(feed\))0 1009 y Fk(Once)20 b(you)f(ha)n(v)o(e)h(an)g
Fh(ElementTree)f Fk(instance,)g(you)h(can)f(call)i(its)g
Fh(getroot\(\))e Fk(method)g(to)i(get)f(the)g(root)f
Fh(Element)h Fk(node.)0 1156 y(There')-5 b(s)26 b(also)g(an)g
Fh(XML\(\))f Fk(function)g(that)h(tak)o(es)g(a)h(string)e(literal)i
(and)e(returns)g(an)h Fh(Element)f Fk(node)g(\(not)h(an)g
Fh(ElementTree)p Fk(\).)0 1255 y(This)20 b(function)f(pro)o(vides)f(a)j
(tidy)f(w)o(ay)g(to)g(incorporate)e(XML)i(fragments,)f(approaching)e
(the)j(con)m(v)o(enience)d(of)j(an)g(XML)h(literal:)236
1493 y Fg(svg)45 b(=)f(ET.XML\("""<svg)f(width="10px")g(version="1.0">)
819 1585 y(</svg>"""\))236 1676 y(svg.set\('height',)f('320px'\))236
1767 y(svg.append\(elem1\))0 2054 y Fk(Each)23 b(XML)h(element)f
(supports)f(some)i(dictionary-lik)o(e)d(and)i(some)h(list-lik)o(e)g
(access)g(methods.)34 b(Dictionary-lik)o(e)22 b(operations)g(are)0
2154 y(used)e(to)g(access)h(attrib)n(ute)f(v)n(alues,)f(and)h(list-lik)
o(e)h(operations)d(are)i(used)g(to)h(access)g(child)e(nodes.)917
2380 y Fi(Operation)p 1770 2410 4 100 v 538 w(Result)p
427 2413 3047 4 v 925 2483 a Fh(elem[n])p 1770 2513 4
100 v 546 w Fk(Returns)h(n')o(th)f(child)h(element.)875
2582 y Fh(elem[m:n])p 1770 2612 V 496 w Fk(Returns)g(list)i(of)e(m')o
(th)f(through)f(n')o(th)h(child)h(elements.)875 2682
y Fh(len\(elem\))p 1770 2712 V 496 w Fk(Returns)g(number)f(of)h(child)g
(elements.)850 2782 y Fh(list\(elem\))p 1770 2812 V 471
w Fk(Returns)g(list)i(of)e(child)f(elements.)651 2881
y Fh(elem.append\(elem2\))p 1770 2911 V 270 w Fk(Adds)h
Ff(elem2)g Fk(as)h(a)g(child.)476 2981 y Fh(elem.insert\(index,)47
b(elem2\))p 1770 3011 V 98 w Fk(Inserts)21 b Ff(elem2)f
Fk(at)g(the)g(speci\002ed)g(location.)825 3081 y Fh(del)49
b(elem[n])p 1770 3110 V 447 w Fk(Deletes)21 b(n')o(th)e(child)h
(element.)825 3180 y Fh(elem.keys\(\))p 1770 3210 V 446
w Fk(Returns)g(list)i(of)e(attrib)n(ute)f(names.)750
3280 y Fh(elem.get\(name\))p 1770 3310 V 371 w Fk(Returns)h(v)n(alue)g
(of)g(attrib)n(ute)g Ff(name)p Fk(.)576 3379 y Fh(elem.set\(name,)47
b(value\))p 1770 3409 V 198 w Fk(Sets)22 b(ne)n(w)e(v)n(alue)f(for)h
(attrib)n(ute)f Ff(name)p Fk(.)825 3479 y Fh(elem.attrib)p
1770 3509 V 446 w Fk(Retrie)n(v)o(es)h(the)h(dictionary)d(containing)g
(attrib)n(utes.)576 3579 y Fh(del)49 b(elem.attrib[name])p
1770 3609 V 196 w Fk(Deletes)21 b(attrib)n(ute)f Ff(name)p
Fk(.)0 3804 y(Comments)i(and)g(processing)g(instructions)f(are)i(also)g
(represented)e(as)i Fh(Element)f Fk(nodes.)32 b(T)-7
b(o)23 b(check)f(if)h(a)g(node)f(is)h(a)h(comment)d(or)0
3903 y(processing)e(instructions:)236 4142 y Fg(if)45
b(elem.tag)e(is)i(ET.Comment:)416 4233 y(...)236 4324
y(elif)f(elem.tag)g(is)g(ET.ProcessingInstruction:)416
4416 y(...)0 4702 y Fk(T)-7 b(o)21 b(generate)e(XML)i(output,)e(you)h
(should)f(call)i(the)g Fh(ElementTree.write\(\))d Fk(method.)24
b(Lik)o(e)d Fh(parse\(\))p Fk(,)f(it)h(can)f(tak)o(e)h(either)0
4802 y(a)g(string)e(or)h(a)h(\002le-lik)o(e)f(object:)p
0 5549 3901 4 v 0 5649 a Fe(13.2)84 b(The)23 b(ElementT)-10
b(ree)24 b(pac)n(kage)2597 b(27)p eop end
%%Page: 28 28
TeXDict begin 28 27 bop 236 83 a Fg(#)45 b(Encoding)e(is)i(US-ASCII)236
174 y(tree.write\('output.xml'\))236 357 y(#)g(Encoding)e(is)i(UTF-8)
236 448 y(f)g(=)g(open\('output.xml',)c('w'\))236 540
y(tree.write\(f,)i(encoding='utf-8'\))0 826 y Fk(\(Caution:)22
b(the)15 b(def)o(ault)g(encoding)f(used)h(for)g(output)f(is)i(ASCII.)g
(F)o(or)f(general)f(XML)i(w)o(ork,)f(where)g(an)h(element')-5
b(s)15 b(name)g(may)g(contain)0 926 y(arbitrary)f(Unicode)h
(characters,)h(ASCII)h(isn')o(t)e(a)i(v)o(ery)e(useful)g(encoding)f
(because)i(it)g(will)h(raise)g(an)f(e)o(xception)e(if)i(an)g(element')
-5 b(s)16 b(name)0 1025 y(contains)h(an)o(y)f(characters)h(with)h(v)n
(alues)f(greater)f(than)h(127.)23 b(Therefore,)16 b(it')-5
b(s)18 b(best)g(to)g(specify)f(a)g(dif)n(ferent)f(encoding)g(such)h(as)
h(UTF-8)0 1125 y(that)i(can)g(handle)f(an)o(y)h(Unicode)f(character)-5
b(.\))0 1272 y(This)21 b(section)g(is)g(only)f(a)i(partial)e
(description)f(of)i(the)g(ElementT)m(ree)e(interf)o(aces.)26
b(Please)c(read)e(the)h(package')-5 b(s)20 b(of)n(\002cial)g
(documenta-)0 1372 y(tion)g(for)f(more)h(details.)0 1518
y Fi(See)h(Also:)0 1665 y Fj(
http://effbot.org/z)o(one)o(/el)o(emen)o
(t-i)o(nd)o(e)n(x.h)o(tm)208 1765 y Fk(Of)n(\002cial)f(documentation)d
(for)j(ElementT)m(ree.)0 2050 y Fc(13.3)100 b(The)29
b(hashlib)g(pac)n(kage)0 2253 y Fk(A)34 b(ne)n(w)g Fh(hashlib)f
Fk(module,)i(written)e(by)h(Gre)o(gory)d(P)-9 b(.)34
b(Smith,)j(has)d(been)f(added)f(to)i(replace)f(the)g
Fh(md5)h Fk(and)f Fh(sha)h Fk(modules.)0 2352 y Fh(hashlib)17
b Fk(adds)g(support)f(for)g(additional)h(secure)f(hashes)i(\(SHA-224,)e
(SHA-256,)g(SHA-384,)h(and)g(SHA-512\).)22 b(When)17
b(a)n(v)n(ailable,)0 2452 y(the)j(module)f(uses)i(OpenSSL)e(for)h(f)o
(ast)h(platform)d(optimized)h(implementations)g(of)g(algorithms.)0
2599 y(The)k(old)g Fh(md5)g Fk(and)g Fh(sha)h Fk(modules)e(still)j(e)o
(xist)e(as)h(wrappers)e(around)g(hashlib)h(to)g(preserv)o(e)f(backw)o
(ards)g(compatibility)-5 b(.)33 b(The)23 b(ne)n(w)0 2698
y(module')-5 b(s)18 b(interf)o(ace)g(is)i(v)o(ery)e(close)h(to)g(that)g
(of)g(the)g(old)f(modules,)g(b)n(ut)h(not)g(identical.)24
b(The)18 b(most)h(signi\002cant)g(dif)n(ference)e(is)j(that)f(the)0
2798 y(constructor)f(functions)h(for)h(creating)f(ne)n(w)h(hashing)f
(objects)h(are)g(named)f(dif)n(ferently)-5 b(.)236 3036
y Fg(#)45 b(Old)f(versions)236 3128 y(h)h(=)g(md5.md5\(\))236
3219 y(h)g(=)g(md5.new\(\))236 3402 y(#)g(New)f(version)236
3493 y(h)h(=)g(hashlib.md5\(\))236 3676 y(#)g(Old)f(versions)236
3767 y(h)h(=)g(sha.sha\(\))236 3858 y(h)g(=)g(sha.new\(\))236
4041 y(#)g(New)f(version)236 4132 y(h)h(=)g(hashlib.sha1\(\))236
4315 y(#)g(Hash)f(that)g(weren't)g(previously)f(available)236
4406 y(h)i(=)g(hashlib.sha224\(\))236 4497 y(h)g(=)g
(hashlib.sha256\(\))236 4589 y(h)g(=)g(hashlib.sha384\(\))236
4680 y(h)g(=)g(hashlib.sha512\(\))236 4863 y(#)g(Alternative)e(form)236
4954 y(h)i(=)g(hashlib.new\('md5'\))445 b(#)45 b(Provide)e(algorithm)g
(as)i(a)g(string)0 5241 y Fk(Once)19 b(a)h(hash)g(object)f(has)h(been)e
(created,)h(its)i(methods)d(are)i(the)f(same)h(as)h(before:)i
Fh(update\()p Ff(string)p Fh(\))18 b Fk(hashes)i(the)g(speci\002ed)f
(string)0 5340 y(into)k(the)g(current)f(digest)h(state,)h
Fh(digest\(\))e Fk(and)g Fh(hexdigest\(\))g Fk(return)g(the)h(digest)g
(v)n(alue)f(as)i(a)f(binary)f(string)h(or)g(a)g(string)g(of)p
0 5549 3901 4 v 0 5649 a Fe(28)2188 b(13)83 b(Ne)n(w)-5
b(,)24 b(Impro)o(v)n(ed,)f(and)g(Remo)o(v)n(ed)g(Modules)p
eop end
%%Page: 29 29
TeXDict begin 29 28 bop 0 83 a Fk(he)o(x)19 b(digits,)h(and)g
Fh(copy\(\))g Fk(returns)f(a)i(ne)n(w)f(hashing)f(object)g(with)i(the)f
(same)g(digest)g(state.)0 230 y Fi(See)h(Also:)0 377
y Fj(../lib/module-hashlib)l(.ht)o(ml)208 476 y Fk(The)e(documentation)
f(for)h(the)h Fh(hashlib)g Fk(module.)0 761 y Fc(13.4)100
b(The)29 b(sqlite3)f(pac)n(kage)0 964 y Fk(The)e(p)o(ysqlite)h(module)e
(\()p Fj(
http://www)l(.p)n(ysqlite)o(.org)-6 b Fk(\),)28
b(a)f(wrapper)f(for)g(the)h(SQLite)g(embedded)d(database,)k(has)f(been)
f(added)g(to)h(the)0 1064 y(standard)19 b(library)g(under)g(the)h
(package)f(name)g Fh(sqlite3)p Fk(.)0 1211 y(SQLite)27
b(is)h(a)f(C)h(library)d(that)i(pro)o(vides)e(a)i(lightweight)f
(disk-based)f(database)h(that)h(doesn')o(t)e(require)h(a)h(separate)f
(serv)o(er)g(process)0 1310 y(and)20 b(allo)n(ws)g(accessing)g(the)g
(database)f(using)h(a)g(nonstandard)e(v)n(ariant)h(of)g(the)i(SQL)f
(query)f(language.)k(Some)d(applications)e(can)i(use)0
1410 y(SQLite)i(for)f(internal)g(data)g(storage.)29 b(It')-5
b(s)22 b(also)g(possible)g(to)f(prototype)f(an)h(application)f(using)i
(SQLite)g(and)f(then)g(port)g(the)g(code)g(to)0 1510
y(a)g(lar)o(ger)d(database)i(such)g(as)h(PostgreSQL)f(or)f(Oracle.)0
1656 y(p)o(ysqlite)25 b(w)o(as)i(written)e(by)h(Gerhard)e(H)5
b(\250)-33 b(aring)25 b(and)g(pro)o(vides)f(a)i(SQL)g(interf)o(ace)f
(compliant)f(with)i(the)f(DB-API)h(2.0)f(speci\002cation)0
1756 y(described)19 b(by)h(PEP)g(249.)0 1903 y(If)26
b(you')l(re)e(compiling)h(the)h(Python)f(source)g(yourself,)h(note)g
(that)g(the)g(source)g(tree)g(doesn')o(t)f(include)g(the)h(SQLite)h
(code,)f(only)g(the)0 2003 y(wrapper)16 b(module.)23
b(Y)-9 b(ou')o(ll)16 b(need)h(to)h(ha)n(v)o(e)e(the)i(SQLite)g
(libraries)f(and)g(headers)f(installed)h(before)f(compiling)g(Python,)h
(and)g(the)g(b)n(uild)0 2102 y(process)j(will)h(compile)e(the)h(module)
f(when)h(the)g(necessary)f(headers)g(are)i(a)n(v)n(ailable.)0
2249 y(T)-7 b(o)25 b(use)h(the)f(module,)f(you)h(must)g(\002rst)h
(create)e(a)i Fh(Connection)e Fk(object)g(that)h(represents)g(the)g
(database.)39 b(Here)25 b(the)g(data)g(will)h(be)0 2349
y(stored)20 b(in)g(the)g(`)p Fj(/tmp/e)n(xample)p Fk(')d(\002le:)236
2587 y Fg(conn)44 b(=)h(sqlite3.connect\('/tmp/example'\))0
2873 y Fk(Y)-9 b(ou)20 b(can)g(also)g(supply)f(the)h(special)h(name)e
(`)p Fh(:memory:)p Fk(')24 b(to)c(create)g(a)h(database)e(in)i(RAM.)0
3020 y(Once)h(you)f(ha)n(v)o(e)h(a)g Fh(Connection)p
Fk(,)f(you)h(can)g(create)g(a)g Fh(Cursor)g Fk(object)f(and)h(call)h
(its)g Fh(execute\(\))e Fk(method)g(to)h(perform)e(SQL)0
3120 y(commands:)236 3358 y Fg(c)45 b(=)g(conn.cursor\(\))236
3541 y(#)g(Create)f(table)236 3632 y(c.execute\('''create)e(table)i
(stocks)236 3723 y(\(date)g(text,)g(trans)g(text,)g(symbol)g(text,)281
3815 y(qty)g(real,)g(price)g(real\)'''\))236 3997 y(#)h(Insert)f(a)g
(row)h(of)f(data)236 4089 y(c.execute\("""insert)e(into)i(stocks)685
4180 y(values)f(\('2006-01-05','BUY','RHAT',100,35.14\)"""\))0
4467 y Fk(Usually)18 b(your)f(SQL)i(operations)e(will)i(need)f(to)h
(use)f(v)n(alues)g(from)g(Python)f(v)n(ariables.)24 b(Y)-9
b(ou)17 b(shouldn')o(t)g(assemble)h(your)f(query)g(using)0
4566 y(Python')-5 b(s)19 b(string)g(operations)f(because)h(doing)f(so)i
(is)h(insecure;)e(it)h(mak)o(es)g(your)e(program)f(vulnerable)h(to)i
(an)f(SQL)h(injection)f(attack.)0 4713 y(Instead,)f(use)h(the)g
(DB-API')-5 b(s)20 b(parameter)d(substitution.)24 b(Put)19
b(`)p Fh(?)p Fk(')24 b(as)c(a)f(placeholder)e(where)n(v)o(er)g(you)h(w)
o(ant)h(to)g(use)g(a)g(v)n(alue,)g(and)f(then)0 4813
y(pro)o(vide)h(a)j(tuple)f(of)g(v)n(alues)g(as)h(the)f(second)f(ar)o
(gument)f(to)j(the)f(cursor')-5 b(s)21 b Fh(execute\(\))f
Fk(method.)27 b(\(Other)20 b(database)h(modules)f(may)0
4912 y(use)g(a)h(dif)n(ferent)e(placeholder)m(,)e(such)j(as)h(`)p
Fh(\045s)p Fk(')f(or)f(`)p Fh(:1)p Fk('.\))25 b(F)o(or)19
b(e)o(xample:)p 0 5549 3901 4 v 0 5649 a Fe(13.4)84 b(The)23
b(sqlite3)h(pac)n(kage)2822 b(29)p eop end
%%Page: 30 30
TeXDict begin 30 29 bop 236 174 a Fg(#)45 b(Never)f(do)g(this)h(--)f
(insecure!)236 266 y(symbol)g(=)h('IBM')236 357 y(c.execute\("...)e
(where)h(symbol)g(=)g('\045s'")g(\045)h(symbol\))236
540 y(#)g(Do)f(this)h(instead)236 631 y(t)g(=)g(\(symbol,\))236
722 y(c.execute\('select)1043 735 y(*)1133 722 y(from)f(stocks)g(where)
g(symbol=?',)f(t\))236 905 y(#)i(Larger)f(example)236
996 y(for)h(t)f(in)h(\(\('2006-03-28',)d('BUY',)i('IBM',)g(1000,)g
(45.00\),)685 1088 y(\('2006-04-05',)e('BUY',)i('MSOFT',)f(1000,)h
(72.00\),)685 1179 y(\('2006-04-06',)e('SELL',)i('IBM',)f(500,)i
(53.00\),)640 1270 y(\):)416 1362 y(c.execute\('insert)d(into)i(stocks)
g(values)f(\(?,?,?,?,?\)',)g(t\))0 1648 y Fk(T)-7 b(o)26
b(retrie)n(v)o(e)e(data)i(after)f(e)o(x)o(ecuting)e(a)j(SELECT)g
(statement,)g(you)f(can)g(either)g(treat)h(the)g(cursor)e(as)i(an)g
(iterator)m(,)g(call)g(the)f(cursor')-5 b(s)0 1748 y
Fh(fetchone\(\))19 b Fk(method)g(to)h(retrie)n(v)o(e)f(a)i(single)f
(matching)f(ro)n(w)-5 b(,)19 b(or)h(call)g Fh(fetchall\(\))f
Fk(to)h(get)h(a)f(list)i(of)d(the)i(matching)d(ro)n(ws.)0
1895 y(This)i(e)o(xample)f(uses)i(the)f(iterator)g(form:)236
2133 y Fg(>>>)45 b(c)f(=)h(conn.cursor\(\))236 2224 y(>>>)g
(c.execute\('select)1223 2237 y(*)1312 2224 y(from)f(stocks)g(order)g
(by)h(price'\))236 2315 y(>>>)g(for)f(row)g(in)h(c:)236
2407 y(...)179 b(print)44 b(row)236 2498 y(...)236 2589
y(\(u'2006-01-05',)f(u'BUY',)g(u'RHAT',)h(100,)g(35.140000000000001\))
236 2681 y(\(u'2006-03-28',)f(u'BUY',)g(u'IBM',)h(1000,)g(45.0\))236
2772 y(\(u'2006-04-06',)f(u'SELL',)g(u'IBM',)h(500,)g(53.0\))236
2863 y(\(u'2006-04-05',)f(u'BUY',)g(u'MSOFT',)h(1000,)f(72.0\))236
2955 y(>>>)0 3241 y Fk(F)o(or)20 b(more)f(information)f(about)h(the)h
(SQL)h(dialect)f(supported)e(by)i(SQLite,)g(see)h Fj(
http://www)l
(.sqlite)o(.org)-6 b Fk(.)0 3388 y Fi(See)21 b(Also:)0
3535 y Fj(
http://www)l(.p)n(ysqlite)o(.org)208 3635 y
Fk(The)e(p)o(ysqlite)h(web)g(page.)0 3781 y Fj(
http://www)l(.sqlite)o
(.org)208 3881 y Fk(The)25 b(SQLite)h(web)g(page;)i(the)e
(documentation)d(describes)j(the)g(syntax)f(and)g(the)h(a)n(v)n
(ailable)g(data)g(types)f(for)h(the)g(supported)208 3981
y(SQL)20 b(dialect.)0 4128 y Fj(../lib/module-sqlite3.)o(html)208
4227 y Fk(The)f(documentation)f(for)h(the)h Fh(sqlite3)g
Fk(module.)0 4374 y(PEP)h(249,)e(\223)p Ff(Database)g(API)h
(Speci\002cation)d(2.0)p Fk(\224)208 4474 y(PEP)j(written)g(by)g
(Marc-Andr)5 b(\264)-33 b(e)18 b(Lemb)n(ur)o(g.)0 4751
y Fc(13.5)100 b(The)29 b(wsgiref)f(pac)n(kage)0 4954
y Fk(The)d(W)-7 b(eb)27 b(Serv)o(er)e(Gate)n(w)o(ay)g(Interf)o(ace)g
(\(WSGI\))g(v1.0)g(de\002nes)g(a)i(standard)d(interf)o(ace)h(between)g
(web)h(serv)o(ers)f(and)g(Python)g(web)0 5054 y(applications)19
b(and)g(is)i(described)e(in)h(PEP)g(333.)k(The)c Fh(wsgiref)f
Fk(package)f(is)j(a)f(reference)f(implementation)e(of)j(the)g(WSGI)h
(speci\002-)0 5154 y(cation.)0 5300 y(The)j(package)e(includes)i(a)g
(basic)h(HTTP)f(serv)o(er)f(that)h(will)h(run)e(a)i(WSGI)g
(application;)f(this)h(serv)o(er)e(is)i(useful)f(for)f(deb)n(ugging)f
(b)n(ut)0 5400 y(isn')o(t)e(intended)f(for)g(production)f(use.)25
b(Setting)20 b(up)g(a)g(serv)o(er)g(tak)o(es)g(only)f(a)i(fe)n(w)f
(lines)h(of)f(code:)p 0 5549 3901 4 v 0 5649 a Fe(30)2188
b(13)83 b(Ne)n(w)-5 b(,)24 b(Impro)o(v)n(ed,)f(and)g(Remo)o(v)n(ed)g
(Modules)p eop end
%%Page: 31 31
TeXDict begin 31 30 bop 236 174 a Fg(from)44 b(wsgiref)g(import)g
(simple_server)236 357 y(wsgi_app)g(=)g(...)236 540 y(host)g(=)h('')236
631 y(port)f(=)h(8000)236 722 y(httpd)f(=)h
(simple_server.make_server\(host,)39 b(port,)44 b(wsgi_app\))236
814 y(httpd.serve_forever\(\))0 1101 y Fi(See)21 b(Also:)0
1248 y Fj(
http://www)l(.wsgi.org)208 1347 y Fk(A)f(central)g(web)g
(site)h(for)f(WSGI-related)f(resources.)0 1494 y(PEP)i(333,)e(\223)p
Ff(Python)g(W)-8 b(eb)20 b(Server)h(Gate)o(way)e(Interface)h(v1.0)p
Fk(\224)208 1594 y(PEP)g(written)g(by)g(Phillip)g(J.)h(Eby)-5
b(.)0 1921 y Fl(14)120 b(Build)33 b(and)i(C)f(API)f(Changes)0
2154 y Fk(Changes)20 b(to)g(Python')-5 b(s)19 b(b)n(uild)h(process)g
(and)g(to)g(the)g(C)h(API)g(include:)125 2384 y Fd(\017)41
b Fk(The)27 b(Python)h(source)f(tree)h(w)o(as)h(con)m(v)o(erted)d(from)
h(CVS)i(to)g(Sub)o(v)o(ersion,)e(in)i(a)g(comple)o(x)d(migration)h
(procedure)e(that)k(w)o(as)208 2483 y(supervised)18 b(and)i(\003a)o
(wlessly)h(carried)e(out)h(by)f(Martin)h(v)n(on)g(L)7
b(\250)-35 b(owis.)25 b(The)20 b(procedure)d(w)o(as)k(de)n(v)o(eloped)d
(as)j(PEP)g(347.)125 2650 y Fd(\017)41 b Fk(Co)o(v)o(erity)-5
b(,)25 b(a)h(compan)o(y)d(that)j(mark)o(ets)f(a)h(source)f(code)g
(analysis)g(tool)h(called)f(Pre)n(v)o(ent,)h(pro)o(vided)d(the)j
(results)g(of)f(their)g(e)o(x-)208 2749 y(amination)d(of)i(the)f
(Python)g(source)g(code.)35 b(The)24 b(analysis)g(found)e(about)h(60)g
(b)n(ugs)h(that)g(were)f(quickly)g(\002x)o(ed.)35 b(Man)o(y)23
b(of)h(the)208 2849 y(b)n(ugs)j(were)h(refcounting)d(problems,)i(often)
g(occurring)f(in)i(error)n(-handling)c(code.)47 b(See)28
b Fj(
http://scan.co)o(v)n(er)q(ity)-7 b(.com)24 b Fk(for)k(the)208
2948 y(statistics.)125 3114 y Fd(\017)41 b Fk(The)25
b(lar)o(gest)h(change)f(to)h(the)g(C)h(API)g(came)e(from)h(PEP)g(353,)h
(which)e(modi\002es)h(the)g(interpreter)f(to)h(use)g(a)h
Fh(Py_ssize_t)208 3214 y Fk(type)19 b(de\002nition)g(instead)h(of)g
Fh(int)p Fk(.)25 b(See)c(the)f(earlier)g(section)g(10)f(for)h(a)h
(discussion)e(of)h(this)h(change.)125 3380 y Fd(\017)41
b Fk(The)21 b(design)f(of)h(the)h(bytecode)d(compiler)h(has)i(changed)e
(a)h(great)g(deal,)h(no)f(longer)f(generating)f(bytecode)h(by)h(tra)n
(v)o(ersing)f(the)208 3480 y(parse)k(tree.)37 b(Instead)24
b(the)g(parse)g(tree)g(is)i(con)m(v)o(erted)21 b(to)k(an)f(abstract)g
(syntax)g(tree)g(\(or)g(AST\),)g(and)g(it)h(is)g(the)f(abstract)g
(syntax)208 3579 y(tree)c(that')-5 b(s)20 b(tra)n(v)o(ersed)g(to)g
(produce)e(the)i(bytecode.)208 3712 y(It')-5 b(s)33 b(possible)g(for)g
(Python)f(code)g(to)i(obtain)e(AST)i(objects)f(by)f(using)h(the)g
Fh(compile\(\))f Fk(b)n(uilt-in)h(and)g(specifying)e
Fh(_-)208 3812 y(ast.PyCF_ONLY_AST)17 b Fk(as)k(the)f(v)n(alue)g(of)g
(the)g Ff(\003a)o(gs)g Fk(parameter:)444 4036 y Fg(from)44
b(_ast)g(import)g(PyCF_ONLY_AST)444 4127 y(ast)g(=)h(compile\("""a=0)
444 4219 y(for)f(i)h(in)f(range\(10\):)623 4310 y(a)h(+=)f(i)444
4401 y(""",)g("<string>",)f('exec',)h(PyCF_ONLY_AST\))444
4584 y(assignment)f(=)i(ast.body[0])444 4675 y(for_loop)e(=)i
(ast.body[1])208 4948 y Fk(No)25 b(of)n(\002cial)g(documentation)d(has)
j(been)g(written)g(for)f(the)h(AST)h(code)e(yet,)i(b)n(ut)g(PEP)f(339)g
(discusses)g(the)h(design.)39 b(T)-7 b(o)25 b(start)208
5047 y(learning)c(about)h(the)g(code,)h(read)f(the)g(de\002nition)g(of)
g(the)h(v)n(arious)f(AST)h(nodes)f(in)g(`)p Fj(P)m(arser/Python.asdl)p
Fk('.)29 b(A)23 b(Python)f(script)208 5147 y(reads)33
b(this)i(\002le)f(and)f(generates)g(a)i(set)f(of)g(C)h(structure)d
(de\002nitions)h(in)h(`)p Fj(Include/Python-ast.h)p Fk('.)61
b(The)34 b Fh(PyParser_-)208 5247 y(ASTFromString\(\))k
Fk(and)h Fh(PyParser_ASTFromFile\(\))p Fk(,)j(de\002ned)d(in)h(`)p
Fj(Include/p)n(ythonr)q(un.h)p Fk(',)f(tak)o(e)i(Python)208
5346 y(source)28 b(as)i(input)e(and)h(return)f(the)h(root)f(of)h(an)g
(AST)h(representing)d(the)i(contents.)51 b(This)29 b(AST)g(can)g(then)g
(be)g(turned)f(into)p 0 5549 3901 4 v 3808 5649 a Fe(31)p
eop end
%%Page: 32 32
TeXDict begin 32 31 bop 208 83 a Fk(a)20 b(code)g(object)g(by)f
Fh(PyAST_Compile\(\))p Fk(.)k(F)o(or)d(more)g(information,)d(read)j
(the)h(source)e(code,)g(and)h(then)g(ask)g(questions)g(on)208
183 y(p)o(ython-de)n(v)-5 b(.)208 315 y(The)19 b(AST)i(code)f(w)o(as)h
(de)n(v)o(eloped)c(under)i(Jeremy)h(Hylton')-5 b(s)20
b(management,)d(and)j(implemented)e(by)i(\(in)g(alphabetical)f(order\))
208 415 y(Brett)25 b(Cannon,)g(Nick)g(Coghlan,)f(Grant)h(Edw)o(ards,)g
(John)f(Ehresman,)g(K)o(urt)h(Kaiser)m(,)g(Neal)h(Norwitz,)f(T)m(im)g
(Peters,)h(Armin)208 515 y(Rigo,)20 b(and)f(Neil)i(Schemenauer)m(,)c
(plus)j(the)h(participants)e(in)h(a)h(number)d(of)i(AST)h(sprints)f(at)
h(conferences)d(such)i(as)h(PyCon.)125 681 y Fd(\017)41
b Fk(Ev)n(an)21 b(Jones')-5 b(s)22 b(patch)g(to)g(obmalloc,)f(\002rst)h
(described)f(in)h(a)h(talk)f(at)g(PyCon)g(DC)h(2005,)e(w)o(as)i
(applied.)29 b(Python)21 b(2.4)g(allocated)208 780 y(small)c(objects)g
(in)h(256K-sized)d(arenas,)i(b)n(ut)g(ne)n(v)o(er)f(freed)g(arenas.)24
b(W)m(ith)17 b(this)h(patch,)f(Python)f(will)i(free)f(arenas)g(when)f
(the)o(y')l(re)208 880 y(empty)-5 b(.)26 b(The)20 b(net)h(ef)n(fect)g
(is)h(that)f(on)f(some)h(platforms,)f(when)g(you)h(allocate)f(man)o(y)g
(objects,)h(Python')-5 b(s)20 b(memory)f(usage)i(may)208
980 y(actually)d(drop)f(when)h(you)g(delete)g(them)h(and)f(the)g
(memory)f(may)i(be)f(returned)f(to)i(the)g(operating)d(system.)25
b(\(Implemented)16 b(by)208 1079 y(Ev)n(an)j(Jones,)h(and)f(re)n(w)o
(ork)o(ed)g(by)h(T)m(im)g(Peters.\))208 1212 y(Note)j(that)h(this)g
(change)f(means)g(e)o(xtension)f(modules)h(must)h(be)f(more)g(careful)g
(when)g(allocating)g(memory)-5 b(.)33 b(Python')-5 b(s)23
b(API)208 1312 y(has)28 b(man)o(y)f(dif)n(ferent)g(functions)g(for)g
(allocating)g(memory)g(that)h(are)h(grouped)c(into)j(f)o(amilies.)50
b(F)o(or)28 b(e)o(xample,)g Fh(PyMem_-)208 1411 y(Malloc\(\))p
Fk(,)i Fh(PyMem_Realloc\(\))p Fk(,)f(and)g Fh(PyMem_Free\(\))f
Fk(are)h(one)g(f)o(amily)f(that)i(allocates)f(ra)o(w)g(memory)-5
b(,)30 b(while)208 1511 y Fh(PyObject_Malloc\(\))p Fk(,)15
b Fh(PyObject_Realloc\(\))p Fk(,)h(and)i Fh(PyObject_Free\(\))e
Fk(are)i(another)f(f)o(amily)g(that')-5 b(s)19 b(sup-)208
1611 y(posed)g(to)h(be)g(used)g(for)g(creating)f(Python)g(objects.)208
1743 y(Pre)n(viously)d(these)j(dif)n(ferent)d(f)o(amilies)i(all)h
(reduced)d(to)j(the)f(platform')-5 b(s)17 b Fh(malloc\(\))g
Fk(and)g Fh(free\(\))h Fk(functions.)23 b(This)18 b(meant)208
1843 y(it)26 b(didn')o(t)e(matter)i(if)g(you)e(got)i(things)f(wrong)f
(and)i(allocated)f(memory)f(with)i(the)f Fh(PyMem)h Fk(function)e(b)n
(ut)h(freed)g(it)i(with)f(the)208 1943 y Fh(PyObject)c
Fk(function.)34 b(W)m(ith)24 b(2.5')-5 b(s)24 b(changes)e(to)i
(obmalloc,)f(these)h(f)o(amilies)g(no)n(w)f(do)g(dif)n(ferent)g(things)
g(and)g(mismatches)208 2042 y(will)d(probably)e(result)j(in)f(a)h(se)o
(gf)o(ault.)j(Y)-9 b(ou)19 b(should)h(carefully)e(test)j(your)e(C)j(e)o
(xtension)c(modules)h(with)i(Python)e(2.5.)125 2208 y
Fd(\017)41 b Fk(The)20 b(b)n(uilt-in)g(set)i(types)f(no)n(w)f(ha)n(v)o
(e)g(an)h(of)n(\002cial)f(C)i(API.)f(Call)h Fh(PySet_New\(\))d
Fk(and)i Fh(PyFrozenSet_New\(\))d Fk(to)j(create)208
2308 y(a)k(ne)n(w)f(set,)j Fh(PySet_Add\(\))c Fk(and)i
Fh(PySet_Discard\(\))d Fk(to)j(add)g(and)f(remo)o(v)o(e)f(elements,)i
(and)g Fh(PySet_Contains)208 2408 y Fk(and)19 b Fh(PySet_Size)g
Fk(to)h(e)o(xamine)f(the)h(set')-5 b(s)22 b(state.)j(\(Contrib)n(uted)
19 b(by)h(Raymond)e(Hettinger)-5 b(.\))125 2574 y Fd(\017)41
b Fk(C)32 b(code)e(can)h(no)n(w)f(obtain)h(information)d(about)i(the)h
(e)o(xact)g(re)n(vision)f(of)h(the)g(Python)f(interpreter)f(by)i
(calling)g(the)g Fh(Py_-)208 2673 y(GetBuildInfo\(\))19
b Fk(function)g(that)i(returns)f(a)i(string)f(of)f(b)n(uild)h
(information)e(lik)o(e)i(this:)28 b Fh("trunk:45355:45356M,)208
2773 y(Apr)49 b(13)g(2006,)g(07:42:19")p Fk(.)24 b(\(Contrib)n(uted)18
b(by)i(Barry)g(W)-7 b(arsa)o(w)i(.\))125 2939 y Fd(\017)41
b Fk(T)-7 b(w)o(o)28 b(ne)n(w)f(macros)g(can)h(be)g(used)f(to)h
(indicate)f(C)i(functions)d(that)i(are)g(local)f(to)h(the)g(current)f
(\002le)h(so)g(that)g(a)g(f)o(aster)g(calling)208 3039
y(con)m(v)o(ention)18 b(can)k(be)f(used.)29 b Fh(Py_LOCAL\()p
Ff(type)p Fh(\))20 b Fk(declares)h(the)h(function)d(as)k(returning)c(a)
j(v)n(alue)f(of)h(the)f(speci\002ed)h Ff(type)f Fk(and)208
3138 y(uses)26 b(a)h(f)o(ast-calling)e(quali\002er)-5
b(.)42 b Fh(Py_LOCAL_INLINE\()p Ff(type)p Fh(\))23 b
Fk(does)j(the)g(same)g(thing)g(and)f(also)h(requests)g(the)g(function)
208 3238 y(be)i(inlined.)49 b(If)29 b Fh(PY_LOCAL_AGGRESSIVE)c
Fk(is)30 b(de\002ned)d(before)g(`)p Fj(p)n(ython.h)p
Fk(')f(is)k(included,)f(a)g(set)g(of)f(more)g(aggressi)n(v)o(e)208
3337 y(optimizations)23 b(are)h(enabled)g(for)f(the)i(module;)g(you)f
(should)g(benchmark)e(the)i(results)h(to)g(\002nd)f(out)g(if)h(these)g
(optimizations)208 3437 y(actually)19 b(mak)o(e)h(the)g(code)g(f)o
(aster)-5 b(.)25 b(\(Contrib)n(uted)19 b(by)g(Fredrik)g(Lundh)g(at)i
(the)f(NeedF)o(orSpeed)e(sprint.\))125 3603 y Fd(\017)41
b Fh(PyErr_NewException\()p Ff(name)p Fh(,)j Ff(base)p
Fh(,)49 b Ff(dict)q Fh(\))24 b Fk(can)f(no)n(w)g(accept)g(a)h(tuple)f
(of)g(base)h(classes)g(as)h(its)f Ff(base)f Fk(ar)o(gument.)208
3703 y(\(Contrib)n(uted)18 b(by)i(Geor)o(g)e(Brandl.\))125
3869 y Fd(\017)41 b Fk(The)66 b Fh(PyErr_Warn\(\))e Fk(function)h(for)g
(issuing)i(w)o(arnings)e(is)i(no)n(w)f(deprecated)e(in)j(f)o(a)n(v)n
(our)e(of)h Fh(PyErr_-)208 3968 y(WarnEx\(category,)46
b(message,)j(stacklevel\))15 b Fk(which)h(lets)h(you)f(specify)g(the)g
(number)f(of)h(stack)h(frames)f(sepa-)208 4068 y(rating)g(this)i
(function)e(and)h(the)h(caller)-5 b(.)24 b(A)18 b Ff(stac)n(kle)o(vel)g
Fk(of)f(1)g(is)i(the)e(function)f(calling)h Fh(PyErr_WarnEx\(\))p
Fk(,)f(2)h(is)i(the)e(function)208 4168 y(abo)o(v)o(e)h(that,)i(and)g
(so)g(forth.)k(\(Added)19 b(by)h(Neal)g(Norwitz.\))125
4334 y Fd(\017)41 b Fk(The)24 b(CPython)g(interpreter)f(is)j(still)g
(written)f(in)g(C,)g(b)n(ut)g(the)g(code)f(can)h(no)n(w)f(be)h
(compiled)e(with)i(a)g(C)3206 4327 y(++)3326 4334 y(compiler)e(without)
208 4433 y(errors.)h(\(Implemented)17 b(by)j(Anthon)o(y)e(Baxter)m(,)i
(Martin)f(v)n(on)h(L)7 b(\250)-35 b(owis,)20 b(Skip)g(Montanaro.\))125
4599 y Fd(\017)41 b Fk(The)20 b Fh(PyRange_New\(\))g
Fk(function)f(w)o(as)j(remo)o(v)o(ed.)k(It)21 b(w)o(as)h(ne)n(v)o(er)e
(documented,)f(ne)n(v)o(er)h(used)h(in)g(the)g(core)g(code,)f(and)h
(had)208 4699 y(dangerously)h(lax)j(error)f(checking.)37
b(In)25 b(the)g(unlik)o(ely)f(case)h(that)h(your)d(e)o(xtensions)h
(were)h(using)f(it,)j(you)d(can)h(replace)f(it)i(by)208
4799 y(something)18 b(lik)o(e)j(the)f(follo)n(wing:)444
5023 y Fg(range)44 b(=)g(PyObject_CallFunction\(\(PyObject)2197
5036 y(*)2242 5023 y(\))c(&PyRange_Type,)i("lll",)1789
5114 y(start,)i(stop,)g(step\);)p 0 5549 3901 4 v 0 5649
a Fe(32)2691 b(14)84 b(Build)24 b(and)g(C)f(API)h(Changes)p
eop end
%%Page: 33 33
TeXDict begin 33 32 bop 0 83 a Fc(14.1)100 b(P)-5 b(or)t(t-Speci\002c)
30 b(Changes)125 269 y Fd(\017)41 b Fk(MacOS)17 b(X)h(\(10.3)e(and)g
(higher\):)22 b(dynamic)16 b(loading)g(of)h(modules)f(no)n(w)h(uses)h
(the)f Fh(dlopen\(\))f Fk(function)g(instead)h(of)g(MacOS-)208
368 y(speci\002c)j(functions.)125 528 y Fd(\017)41 b
Fk(MacOS)21 b(X:)h(a)g Fi(--enable-uni)o(v)o(ersalsdk)f
Fk(switch)h(w)o(as)g(added)f(to)g(the)h Fi(con\002gur)o(e)f
Fk(script)g(that)h(compiles)f(the)g(interpreter)f(as)i(a)208
627 y(uni)n(v)o(ersal)c(binary)h(able)h(to)h(run)e(on)h(both)f(Po)n
(werPC)i(and)e(Intel)h(processors.)k(\(Contrib)n(uted)18
b(by)i(Ronald)g(Oussoren.\))125 787 y Fd(\017)41 b Fk(W)m(indo)n(ws:)34
b(`)p Fj(.dll)p Fk(')24 b(is)i(no)f(longer)f(supported)f(as)j(a)g
(\002lename)e(e)o(xtension)g(for)h(e)o(xtension)e(modules.)39
b(`)p Fj(.p)n(yd)p Fk(')24 b(is)i(no)n(w)f(the)g(only)208
886 y(\002lename)19 b(e)o(xtension)g(that)h(will)h(be)f(searched)f(for)
-5 b(.)0 1211 y Fl(15)120 b(P)-6 b(or)5 b(ting)34 b(to)g(Python)h(2.5)0
1443 y Fk(This)20 b(section)g(lists)i(pre)n(viously)c(described)h
(changes)g(that)h(may)g(require)f(changes)g(to)i(your)d(code:)125
1657 y Fd(\017)41 b Fk(ASCII)20 b(is)i(no)n(w)e(the)h(def)o(ault)e
(encoding)g(for)h(modules.)25 b(It')-5 b(s)21 b(no)n(w)f(a)h(syntax)f
(error)f(if)i(a)g(module)e(contains)h(string)g(literals)h(with)208
1756 y(8-bit)h(characters)g(b)n(ut)h(doesn')o(t)e(ha)n(v)o(e)h(an)h
(encoding)e(declaration.)31 b(In)23 b(Python)e(2.4)i(this)g(triggered)e
(a)i(w)o(arning,)f(not)h(a)g(syntax)208 1856 y(error)-5
b(.)125 2015 y Fd(\017)41 b Fk(Pre)n(viously)-5 b(,)17
b(the)i Fh(gi_frame)e Fk(attrib)n(ute)i(of)f(a)i(generator)d(w)o(as)i
(al)o(w)o(ays)h(a)f(frame)f(object.)24 b(Because)19 b(of)f(the)h(PEP)h
(342)e(changes)208 2115 y(described)g(in)j(section)f(7,)g(it')-5
b(s)21 b(no)n(w)f(possible)g(for)f Fh(gi_frame)g Fk(to)i(be)f
Fh(None)p Fk(.)125 2274 y Fd(\017)41 b Fk(A)22 b(ne)n(w)g(w)o(arning,)f
Fh(UnicodeWarning)p Fk(,)g(is)i(triggered)d(when)i(you)f(attempt)h(to)g
(compare)f(a)i(Unicode)e(string)g(and)h(an)g(8-bit)208
2374 y(string)17 b(that)h(can')o(t)f(be)h(con)m(v)o(erted)d(to)j
(Unicode)f(using)g(the)h(def)o(ault)f(ASCII)h(encoding.)k(Pre)n
(viously)17 b(such)g(comparisons)f(w)o(ould)208 2474
y(raise)k(a)h Fh(UnicodeDecodeError)c Fk(e)o(xception.)125
2633 y Fd(\017)41 b Fk(Library:)23 b(the)c Fh(csv)h Fk(module)e(is)i
(no)n(w)f(stricter)h(about)e(multi-line)g(quoted)g(\002elds.)26
b(If)19 b(your)f(\002les)i(contain)f(ne)n(wlines)g(embedded)208
2733 y(within)h(\002elds,)g(the)g(input)g(should)f(be)h(split)h(into)f
(lines)g(in)h(a)f(manner)f(which)h(preserv)o(es)f(the)h(ne)n(wline)f
(characters.)125 2892 y Fd(\017)41 b Fk(Library:)30 b(the)24
b Fh(locale)f Fk(module')-5 b(s)22 b Fh(format\(\))h
Fk(function')-5 b(s)22 b(w)o(ould)h(pre)n(viously)f(accept)h(an)o(y)g
(string)g(as)h(long)f(as)h(no)f(more)208 2992 y(than)h(one)h(\045char)f
(speci\002er)h(appeared.)38 b(In)25 b(Python)e(2.5,)j(the)f(ar)o
(gument)e(must)i(be)g(e)o(xactly)f(one)g(\045char)h(speci\002er)g(with)
g(no)208 3091 y(surrounding)17 b(te)o(xt.)125 3251 y
Fd(\017)41 b Fk(Library:)22 b(The)17 b Fh(pickle)g Fk(and)g
Fh(cPickle)f Fk(modules)g(no)h(longer)f(accept)h(a)h(return)e(v)n(alue)
h(of)g Fh(None)g Fk(from)g(the)g Fh(__reduce_-)208 3350
y(_\(\))29 b Fk(method;)j(the)e(method)e(must)h(return)f(a)i(tuple)f
(of)g(ar)o(guments)e(instead.)52 b(The)29 b(modules)f(also)i(no)f
(longer)f(accept)h(the)208 3450 y(deprecated)18 b Ff(bin)i
Fk(k)o(e)o(yw)o(ord)e(parameter)-5 b(.)125 3609 y Fd(\017)41
b Fk(Library:)29 b(The)22 b Fh(SimpleXMLRPCServer)e Fk(and)j
Fh(DocXMLRPCServer)d Fk(classes)k(no)n(w)f(ha)n(v)o(e)f(a)h
Fh(rpc_paths)f Fk(attrib)n(ute)208 3709 y(that)32 b(constrains)g
(XML-RPC)h(operations)e(to)i(a)g(limited)g(set)g(of)f(URL)i(paths;)k
(the)33 b(def)o(ault)f(is)h(to)g(allo)n(w)g(only)e Fh('/')i
Fk(and)208 3809 y Fh('/RPC2')p Fk(.)24 b(Setting)c Fh(rpc_paths)f
Fk(to)h Fh(None)g Fk(or)g(an)g(empty)g(tuple)f(disables)i(this)f(path)g
(checking.)125 3968 y Fd(\017)41 b Fk(C)27 b(API:)f(Man)o(y)f
(functions)g(no)n(w)h(use)g Fh(Py_ssize_t)f Fk(instead)h(of)g
Fh(int)g Fk(to)g(allo)n(w)g(processing)f(more)g(data)h(on)g(64-bit)f
(ma-)208 4068 y(chines.)32 b(Extension)21 b(code)h(may)g(need)g(to)h
(mak)o(e)f(the)h(same)g(change)e(to)i(a)n(v)n(oid)f(w)o(arnings)g(and)g
(to)h(support)e(64-bit)h(machines.)208 4167 y(See)e(the)g(earlier)g
(section)g(10)g(for)f(a)i(discussion)f(of)g(this)g(change.)125
4327 y Fd(\017)41 b Fk(C)36 b(API:)g(The)f(obmalloc)f(changes)g(mean)h
(that)h(you)e(must)i(be)f(careful)f(to)i(not)f(mix)g(usage)g(of)g(the)h
Fh(PyMem_)3596 4342 y(*)3646 4327 y(\(\))e Fk(and)208
4426 y Fh(PyObject_)658 4441 y(*)708 4426 y(\(\))28 b
Fk(f)o(amilies)j(of)f(functions.)54 b(Memory)29 b(allocated)g(with)i
(one)f(f)o(amily')-5 b(s)2899 4441 y Fh(*)2949 4426 y(_Malloc\(\))29
b Fk(must)h(be)g(freed)208 4526 y(with)20 b(the)g(corresponding)d(f)o
(amily')-5 b(s)1286 4541 y Fh(*)1336 4526 y(_Free\(\))19
b Fk(function.)0 4850 y Fl(16)120 b(Ac)n(kno)n(wledgements)0
5083 y Fk(The)21 b(author)g(w)o(ould)f(lik)o(e)i(to)g(thank)f(the)g
(follo)n(wing)f(people)h(for)g(of)n(fering)e(suggestions,)i
(corrections)f(and)h(assistance)h(with)g(v)n(arious)0
5183 y(drafts)d(of)g(this)g(article:)25 b(Geor)o(g)18
b(Brandl,)g(Nick)h(Coghlan,)f(Phillip)i(J.)f(Eby)-5 b(,)18
b(Lars)i(Gust)5 b(\250)-33 b(abel,)18 b(Raymond)g(Hettinger)m(,)g(Ralf)
i(W)-8 b(.)20 b(Grosse-)0 5282 y(K)o(unstle)n(v)o(e,)15
b(K)n(ent)g(Johnson,)g(Iain)g(Lo)n(we,)g(Martin)g(v)n(on)g(L)7
b(\250)-35 b(owis,)16 b(Fredrik)e(Lundh,)g(Andre)n(w)h(McNamara,)g
(Skip)g(Montanaro,)f(Gusta)n(v)n(o)0 5382 y(Nieme)o(yer)m(,)k(P)o(aul)i
(Prescod,)g(James)g(Pryor)m(,)f(Mik)o(e)h(Ro)o(vner)m(,)f(Scott)h(W)-7
b(eikart,)20 b(Barry)g(W)-7 b(arsa)o(w)i(,)20 b(Thomas)g(W)-7
b(outers.)p 0 5549 3901 4 v 0 5649 a Fe(14.1)84 b(P)l(or)s
(t-Speci\002c)22 b(Changes)2739 b(33)p eop end
%%Trailer
userdict /end-hook known{end-hook}if
%%EOF