lib.pdf

(3939 KB) Pobierz
Python Library Reference
PythonLibraryReference
Release2.5
GuidovanRossum
FredL.Drake,Jr.,editor
19thSeptember,2006
PythonSoftwareFoundation
Email: docs@python.org
Copyrightc 2001-2006PythonSoftwareFoundation.Allrightsreserved.
Copyright c 2000BeOpen.com.Allrightsreserved.
Copyrightc 1995-2000CorporationforNationalResearchInitiatives.Allrightsreserved.
Copyright c 1991-1995StichtingMathematischCentrum.Allrightsreserved.
Seetheendofthisdocumentforcompletelicenseandpermissionsinformation.
Abstract
Pythonisanextensible,interpreted,object-orientedprogramminglanguage.Itsupportsawiderangeofapplica-
tions,fromsimpletextprocessingscriptstointeractiveWebbrowsers.
Whilethe PythonReferenceManual describestheexactsyntaxandsemanticsofthelanguage,itdoesnotdescribe
thestandardlibrarythatisdistributedwiththelanguage,andwhichgreatlyenhancesitsimmediateusability.
Thislibrarycontainsbuilt-inmodules(writteninC)thatprovideaccesstosystemfunctionalitysuchasfileI/O
thatwouldotherwisebeinaccessibletoPythonprogrammers,aswellasmoduleswritteninPythonthatprovide
standardizedsolutionsformanyproblemsthatoccurineverydayprogramming.Someofthesemodulesare
explicitlydesignedtoencourageandenhancetheportabilityofPythonprograms.
ThislibraryreferencemanualdocumentsPython’sstandardlibrary,aswellasmanyoptionallibrarymodules
(whichmayormaynotbeavailable,dependingonwhethertheunderlyingplatformsupportsthemandonthe
configurationchoicesmadeatcompiletime).Italsodocumentsthestandardtypesofthelanguageanditsbuilt-in
functionsandexceptions,manyofwhicharenotorincompletelydocumentedintheReferenceManual.
ThismanualassumesbasicknowledgeaboutthePythonlanguage.ForaninformalintroductiontoPython,seethe
PythonTutorial ; the PythonReferenceManual remainsthehighestauthorityonsyntacticandsemanticquestions.
Finally,themanualentitled ExtendingandEmbeddingthePythonInterpreter describeshowtoaddnewextensions
toPythonandhowtoembeditinotherapplications.
CONTENTS
1Introduction
1
2Built-inObjects 3
2.1Built-inFunctions .......................................... 3
2.2Non-essentialBuilt-inFunctions .................................. 16
2.3Built-inExceptions .......................................... 16
2.4Built-inConstants .......................................... 20
3Built-inTypes 23
3.1TruthValueTesting .......................................... 23
3.2BooleanOperations— and , or , not ............................... 23
3.3Comparisons ............................................. 24
3.4NumericTypes— int , float , long , complex ........................ 24
3.5 IteratorTypes ............................................ 26
3.6SequenceTypes— str , unicode , list , tuple , buffer , xrange ............. 27
3.7SetTypes— set , frozenset .................................. 35
3.8MappingTypes— dict ...................................... 36
3.9FileObjects ............................................. 38
3.10ContextManagerTypes ....................................... 40
3.11OtherBuilt-inTypes ......................................... 41
3.12SpecialAttributes .......................................... 43
4StringServices 45
4.1 string —Commonstringoperations ............................... 45
4.2 re —Regularexpressionoperations ................................ 50
4.3 struct —Interpretstringsaspackedbinarydata ......................... 60
4.4 difflib —Helpersforcomputingdeltas ............................. 62
4.5 StringIO —Readandwritestringsasfiles ............................ 70
4.6 cStringIO —Fasterversionof StringIO ........................... 70
4.7 textwrap —Textwrappingandfilling .............................. 71
4.8 codecs —Codecregistryandbaseclasses ............................ 73
4.9 unicodedata —UnicodeDatabase ............................... 85
4.10 stringprep —InternetStringPreparation ............................ 86
4.11 fpformat —Floatingpointconversions ............................. 88
5DataTypes 89
5.1 datetime —Basicdateandtimetypes .............................. 89
5.2 calendar —Generalcalendar-relatedfunctions .........................106
5.3 collections —High-performancecontainerdatatypes .....................109
5.4 heapq —Heapqueuealgorithm ..................................114
5.5 bisect —Arraybisectionalgorithm ...............................116
5.6 array —Efficientarraysofnumericvalues ............................117
5.7 sets —Unorderedcollectionsofuniqueelements .........................120
5.8 sched —Eventscheduler .....................................123
i
Zgłoś jeśli naruszono regulamin