Python 標準函式庫(Standard Library)

文章推薦指數: 80 %
投票人數:10人

Python 的標準函式庫是非常龐大的,其提供了如下所述極多且涵蓋用途極廣的許多模組。

包含一些用C 語言撰寫,可以操作像是檔案讀寫等系統相關功能的內建模組,當然也有 ... 瀏覽 索引 模組| 下一頁| 上一頁| Python» zh_TW 3.7.0 Documentation» | Python標準函式庫(StandardLibrary)¶ ThePythonLanguageReference說明Python這門語言確切的文法及語意,而這份函式庫參考手冊則是說明隨著Python一起發佈的標準函式庫,除此之外,其內容也包含一些時常出現在Python發佈版本中的非必要套件。

Python的標準函式庫是非常龐大的,其提供了如下所述極多且涵蓋用途極廣的許多模組。

包含一些用C語言撰寫,可以操作像是檔案讀寫等系統相關功能的內建模組,當然也有用Python撰寫,並使用標準解法解決許多常見問題的模組。

其中有些模組則是特別針對Python的可攜性去設計的,為此特地將一些平台特殊相依性的功能抽象化成可跨平台的API。

Python的Windows安裝檔基本上包含整個標準函式庫,且通常也包含許多額外套件;而類Unix作業系統方面,Python則提供一系列的套件,對於某些非必要性的套件,可能得使用該作業系統提供的套件管理工具來安裝。

Inadditiontothestandardlibrary,thereisagrowingcollectionof severalthousandcomponents(fromindividualprogramsandmodulesto packagesandentireapplicationdevelopmentframeworks),availablefrom thePythonPackageIndex. 1.簡介 2.內建函式 3.內建常數 3.1.Constantsaddedbythesitemodule 4.內建型態 4.1.TruthValueTesting 4.2.BooleanOperations—and,or,not 4.3.Comparisons 4.4.NumericTypes—int,float,complex 4.5.IteratorTypes 4.6.SequenceTypes—list,tuple,range 4.7.TextSequenceType—str 4.8.BinarySequenceTypes—bytes,bytearray,memoryview 4.9.SetTypes—set,frozenset 4.10.MappingTypes—dict 4.11.ContextManagerTypes 4.12.OtherBuilt-inTypes 4.13.SpecialAttributes 5.內建的例外 5.1.Baseclasses 5.2.Concreteexceptions 5.3.Warnings 5.4.Exceptionhierarchy 6.TextProcessingServices 6.1.string—Commonstringoperations 6.2.re—Regularexpressionoperations 6.3.difflib—Helpersforcomputingdeltas 6.4.textwrap—Textwrappingandfilling 6.5.unicodedata—UnicodeDatabase 6.6.stringprep—InternetStringPreparation 6.7.readline—GNUreadlineinterface 6.8.rlcompleter—CompletionfunctionforGNUreadline 7.BinaryDataServices 7.1.struct—Interpretbytesaspackedbinarydata 7.2.codecs—Codecregistryandbaseclasses 8.DataTypes 8.1.datetime—Basicdateandtimetypes 8.2.calendar—Generalcalendar-relatedfunctions 8.3.collections—容器資料型態 8.4.collections.abc—AbstractBaseClassesforContainers 8.5.heapq—堆積佇列(heapqueue)演算法 8.6.bisect—陣列二分演算法(Arraybisectionalgorithm) 8.7.array—高效率的數值型態陣列 8.8.weakref—Weakreferences 8.9.types—Dynamictypecreationandnamesforbuilt-intypes 8.10.copy—Shallowanddeepcopyoperations 8.11.pprint—Dataprettyprinter 8.12.reprlib—Alternaterepr()implementation 8.13.enum—Supportforenumerations 9.數值與數學模組 9.1.numbers—Numericabstractbaseclasses 9.2.math—Mathematicalfunctions 9.3.cmath—Mathematicalfunctionsforcomplexnumbers 9.4.decimal—Decimalfixedpointandfloatingpointarithmetic 9.5.fractions—Rationalnumbers 9.6.random—Generatepseudo-randomnumbers 9.7.statistics—數學統計函式 10.函式編程模組 10.1.itertools—Functionscreatingiteratorsforefficientlooping 10.2.functools—Higher-orderfunctionsandoperationsoncallableobjects 10.3.operator—Standardoperatorsasfunctions 11.檔案與目錄存取 11.1.pathlib—Object-orientedfilesystempaths 11.2.os.path—Commonpathnamemanipulations 11.3.fileinput—Iterateoverlinesfrommultipleinputstreams 11.4.stat—Interpretingstat()results 11.5.filecmp—FileandDirectoryComparisons 11.6.tempfile—Generatetemporaryfilesanddirectories 11.7.glob—Unixstylepathnamepatternexpansion 11.8.fnmatch—Unixfilenamepatternmatching 11.9.linecache—Randomaccesstotextlines 11.10.shutil—High-levelfileoperations 11.11.macpath—MacOS9pathmanipulationfunctions 12.DataPersistence 12.1.pickle—Pythonobjectserialization 12.2.copyreg—Registerpicklesupportfunctions 12.3.shelve—Pythonobjectpersistence 12.4.marshal—InternalPythonobjectserialization 12.5.dbm—InterfacestoUnix「databases」 12.6.sqlite3—DB-API2.0interfaceforSQLitedatabases 13.資料壓縮與保存 13.1.zlib—Compressioncompatiblewithgzip 13.2.gzip—Supportforgzipfiles 13.3.bz2—Supportforbzip2compression 13.4.lzma—CompressionusingtheLZMAalgorithm 13.5.zipfile—WorkwithZIParchives 13.6.tarfile—Readandwritetararchivefiles 14.檔案格式 14.1.csv—CSVFileReadingandWriting 14.2.configparser—Configurationfileparser 14.3.netrc—netrcfileprocessing 14.4.xdrlib—EncodeanddecodeXDRdata 14.5.plistlib—GenerateandparseMacOSX.plistfiles 15.CryptographicServices 15.1.hashlib—Securehashesandmessagedigests 15.2.hmac—Keyed-HashingforMessageAuthentication 15.3.secrets—Generatesecurerandomnumbersformanagingsecrets 16.GenericOperatingSystemServices 16.1.os—Miscellaneousoperatingsysteminterfaces 16.2.io—Coretoolsforworkingwithstreams 16.3.time—Timeaccessandconversions 16.4.argparse—Parserforcommand-lineoptions,argumentsandsub-commands 16.5.getopt—C-styleparserforcommandlineoptions 16.6.logging—LoggingfacilityforPython 16.7.logging.config—Loggingconfiguration 16.8.logging.handlers—Logginghandlers 16.9.getpass—Portablepasswordinput 16.10.curses—Terminalhandlingforcharacter-celldisplays 16.11.curses.textpad—Textinputwidgetforcursesprograms 16.12.curses.ascii—UtilitiesforASCIIcharacters 16.13.curses.panel—Apanelstackextensionforcurses 16.14.platform—Accesstounderlyingplatform’sidentifyingdata 16.15.errno—Standarderrnosystemsymbols 16.16.ctypes—AforeignfunctionlibraryforPython 17.ConcurrentExecution 17.1.threading—Thread-basedparallelism 17.2.multiprocessing—Process-basedparallelism 17.3.Theconcurrentpackage 17.4.concurrent.futures—Launchingparalleltasks 17.5.subprocess—Subprocessmanagement 17.6.sched—Eventscheduler 17.7.queue—Asynchronizedqueueclass 17.8._thread—Low-levelthreadingAPI 17.9._dummy_thread—Drop-inreplacementforthe_threadmodule 17.10.dummy_threading—Drop-inreplacementforthethreadingmodule 18.contextvars—ContextVariables 18.1.ContextVariables 18.2.ManualContextManagement 18.3.asynciosupport 19.InterprocessCommunicationandNetworking 19.1.socket—Low-levelnetworkinginterface 19.2.ssl—TLS/SSLwrapperforsocketobjects 19.3.select—WaitingforI/Ocompletion 19.4.selectors—High-levelI/Omultiplexing 19.5.asyncio—AsynchronousI/O,eventloop,coroutinesandtasks 19.6.asyncore—Asynchronoussockethandler 19.7.asynchat—Asynchronoussocketcommand/responsehandler 19.8.signal—Sethandlersforasynchronousevents 19.9.mmap—Memory-mappedfilesupport 20.InternetDataHandling 20.1.email—AnemailandMIMEhandlingpackage 20.2.json—JSONencoderanddecoder 20.3.mailcap—Mailcapfilehandling 20.4.mailbox—Manipulatemailboxesinvariousformats 20.5.mimetypes—MapfilenamestoMIMEtypes 20.6.base64——Base16、Base32、Base64、Base85資料編碼 20.7.binhex—Encodeanddecodebinhex4files 20.8.binascii—ConvertbetweenbinaryandASCII 20.9.quopri—EncodeanddecodeMIMEquoted-printabledata 20.10.uu—Encodeanddecodeuuencodefiles 21.StructuredMarkupProcessingTools 21.1.html—HyperTextMarkupLanguagesupport 21.2.html.parser—SimpleHTMLandXHTMLparser 21.3.html.entities—DefinitionsofHTMLgeneralentities 21.4.XML處理模組 21.5.xml.etree.ElementTree—TheElementTreeXMLAPI 21.6.xml.dom—TheDocumentObjectModelAPI 21.7.xml.dom.minidom—MinimalDOMimplementation 21.8.xml.dom.pulldom—SupportforbuildingpartialDOMtrees 21.9.xml.sax—SupportforSAX2parsers 21.10.xml.sax.handler—BaseclassesforSAXhandlers 21.11.xml.sax.saxutils—SAXUtilities 21.12.xml.sax.xmlreader—InterfaceforXMLparsers 21.13.xml.parsers.expat—FastXMLparsingusingExpat 22.InternetProtocolsandSupport 22.1.webbrowser—ConvenientWeb-browsercontroller 22.2.cgi—CommonGatewayInterfacesupport 22.3.cgitb—TracebackmanagerforCGIscripts 22.4.wsgiref—WSGIUtilitiesandReferenceImplementation 22.5.urllib—URLhandlingmodules 22.6.urllib.request—ExtensiblelibraryforopeningURLs 22.7.urllib.response—Responseclassesusedbyurllib 22.8.urllib.parse—ParseURLsintocomponents 22.9.urllib.error—Exceptionclassesraisedbyurllib.request 22.10.urllib.robotparser—Parserforrobots.txt 22.11.http—HTTPmodules 22.12.http.client—HTTPprotocolclient 22.13.ftplib—FTPprotocolclient 22.14.poplib—POP3protocolclient 22.15.imaplib—IMAP4protocolclient 22.16.nntplib—NNTPprotocolclient 22.17.smtplib—SMTPprotocolclient 22.18.smtpd—SMTPServer 22.19.telnetlib—Telnetclient 22.20.uuid—UUIDobjectsaccordingtoRFC4122 22.21.socketserver—Aframeworkfornetworkservers 22.22.http.server—HTTPservers 22.23.http.cookies—HTTPstatemanagement 22.24.http.cookiejar—CookiehandlingforHTTPclients 22.25.xmlrpc—XMLRPCserverandclientmodules 22.26.xmlrpc.client—XML-RPCclientaccess 22.27.xmlrpc.server—BasicXML-RPCservers 22.28.ipaddress—IPv4/IPv6manipulationlibrary 23.MultimediaServices 23.1.audioop—Manipulaterawaudiodata 23.2.aifc—ReadandwriteAIFFandAIFCfiles 23.3.sunau—ReadandwriteSunAUfiles 23.4.wave—ReadandwriteWAVfiles 23.5.chunk—ReadIFFchunkeddata 23.6.colorsys—Conversionsbetweencolorsystems 23.7.imghdr—Determinethetypeofanimage 23.8.sndhdr—Determinetypeofsoundfile 23.9.ossaudiodev—AccesstoOSS-compatibleaudiodevices 24.國際化 24.1.gettext—Multilingualinternationalizationservices 24.2.locale—Internationalizationservices 25.程式框架 25.1.turtle—龜圖學 25.2.cmd—Supportforline-orientedcommandinterpreters 25.3.shlex—Simplelexicalanalysis 26.以Tk打造GUI 26.1.tkinter—PythoninterfacetoTcl/Tk 26.2.tkinter.ttk—Tkthemedwidgets 26.3.tkinter.tix—ExtensionwidgetsforTk 26.4.tkinter.scrolledtext—ScrolledTextWidget 26.5.IDLE 26.6.其它的GUI 27.開發工具 27.1.typing—Supportfortypehints 27.2.pydoc—Documentationgeneratorandonlinehelpsystem 27.3.doctest—TestinteractivePythonexamples 27.4.unittest—單元測試框架 27.5.unittest.mock—mockobjectlibrary 27.6.unittest.mock—gettingstarted 27.7.2to3-自動將Python2的程式碼轉成Python3 27.8.test—RegressiontestspackageforPython 27.9.test.support—UtilitiesforthePythontestsuite 27.10.test.support.script_helper—UtilitiesforthePythonexecutiontests 28.DebuggingandProfiling 28.1.bdb—Debuggerframework 28.2.faulthandler—DumpthePythontraceback 28.3.pdb—ThePythonDebugger 28.4.ThePythonProfilers 28.5.timeit—Measureexecutiontimeofsmallcodesnippets 28.6.trace—TraceortrackPythonstatementexecution 28.7.tracemalloc—Tracememoryallocations 29.軟體封裝與發布 29.1.distutils—BuildingandinstallingPythonmodules 29.2.ensurepip—Bootstrappingthepipinstaller 29.3.venv—Creationofvirtualenvironments 29.4.zipapp—Manageexecutablepythonziparchives 30.PythonRuntimeServices 30.1.sys—System-specificparametersandfunctions 30.2.sysconfig—ProvideaccesstoPython’sconfigurationinformation 30.3.builtins—Built-inobjects 30.4.__main__—Top-levelscriptenvironment 30.5.warnings—Warningcontrol 30.6.dataclasses—DataClasses 30.7.contextlib—Utilitiesforwith-statementcontexts 30.8.abc—AbstractBaseClasses 30.9.atexit—Exithandlers 30.10.traceback—Printorretrieveastacktraceback 30.11.__future__—Futurestatementdefinitions 30.12.gc—GarbageCollectorinterface 30.13.inspect—Inspectliveobjects 30.14.site—Site-specificconfigurationhook 31.CustomPythonInterpreters 31.1.code—Interpreterbaseclasses 31.2.codeop—CompilePythoncode 32.匯入模組 32.1.zipimport—ImportmodulesfromZiparchives 32.2.pkgutil—Packageextensionutility 32.3.modulefinder—Findmodulesusedbyascript 32.4.runpy—LocatingandexecutingPythonmodules 32.5.importlib—Theimplementationofimport 33.PythonLanguageServices 33.1.parser—AccessPythonparsetrees 33.2.ast—AbstractSyntaxTrees 33.3.symtable—Accesstothecompiler’ssymboltables 33.4.symbol—ConstantsusedwithPythonparsetrees 33.5.token—ConstantsusedwithPythonparsetrees 33.6.keyword—TestingforPythonkeywords 33.7.tokenize—TokenizerforPythonsource 33.8.tabnanny—Detectionofambiguousindentation 33.9.pyclbr—Pythonclassbrowsersupport 33.10.py_compile—CompilePythonsourcefiles 33.11.compileall—Byte-compilePythonlibraries 33.12.dis—Pythonbytecode的反組譯器 33.13.pickletools—Toolsforpickledevelopers 34.MiscellaneousServices 34.1.formatter—Genericoutputformatting 35.MSWindowsSpecificServices 35.1.msilib—ReadandwriteMicrosoftInstallerfiles 35.2.msvcrt—UsefulroutinesfromtheMSVC++runtime 35.3.winreg—Windowsregistryaccess 35.4.winsound—Sound-playinginterfaceforWindows 36.UnixSpecificServices 36.1.posix—ThemostcommonPOSIXsystemcalls 36.2.pwd—Thepassworddatabase 36.3.spwd—Theshadowpassworddatabase 36.4.grp—Thegroupdatabase 36.5.crypt—FunctiontocheckUnixpasswords 36.6.termios—POSIXstylettycontrol 36.7.tty—Terminalcontrolfunctions 36.8.pty—Pseudo-terminalutilities 36.9.fcntl—Thefcntlandioctlsystemcalls 36.10.pipes—Interfacetoshellpipelines 36.11.resource—Resourceusageinformation 36.12.nis—InterfacetoSun’sNIS(YellowPages) 36.13.syslog—Unixsysloglibraryroutines 37.SupersededModules 37.1.optparse—Parserforcommandlineoptions 37.2.imp—Accesstheimportinternals 38.UndocumentedModules 38.1.Platformspecificmodules 上個主題 10.完整的語法規格書 下個主題 1.簡介 ThisPage ReportaBug ShowSource 瀏覽 索引 模組| 下一頁| 上一頁| Python» zh_TW 3.7.0 Documentation» |



請為這篇文章評分?