By Doug Hellmann
“Hellmann’s writing has develop into an integral source for me and so on because it fills a serious hole in Python Documentation with examples.”
– Jesse Noller, Python middle Developer and PSF Board Member
Master the strong Python common Library via genuine Code Examples
The Python common Library comprises hundreds and hundreds of modules for interacting with the working process, interpreter, and Internet–all largely demonstrated and able to jump-start your software improvement. The Python general Library via instance (2 quantity Set) introduces nearly each vital sector of the Python 2.7 library via concise, stand-alone resource code/output examples, designed for simple studying and reuse.
Building on his renowned Python Module of the Week blog sequence, writer and Python professional Doug Hellmann makes a speciality of “showing” now not “telling.” He explains code habit via downloadable examples that totally reveal each one feature.
You’ll locate sensible code for operating with textual content, information kinds, algorithms, math, dossier structures, networking, the web, XML, e mail, cryptography, concurrency, runtime and language companies, and masses extra. every one part totally covers one module, and hyperlinks to priceless extra assets, making this e-book a terrific educational and reference. insurance includes
Manipulating textual content with string, textwrap, re, and difflib
Implementing facts buildings: collections, array, queue, struct, replica, and more
Reading, writing, and manipulating documents and directories
Regular expression development matching
Exchanging facts and offering for patience Archiving and information compression
Managing approaches and threads
Using software “building blocks”: parsing command-line suggestions, prompting for passwords, scheduling occasions, and logging
Testing, debugging, and compilation
Controlling runtime configuration
Using module and package deal utilities
If you’re new to Python, this e-book will fast offer you entry to an entire new international of performance. If you’ve labored with Python ahead of, you’ll observe new, strong ideas and higher how you can use the modules you’ve already tried.
Quick preview of The Python Standard Library by Example PDF
Best Python books
Exploring Python takes an energetic studying process which engages the scholar as an equivalent accomplice within the technique of studying the joys, academic, and strong programming language. This process instills behavior that scholars will hold with them all through their programming profession and is helping them maintain and use the data they've got discovered.
Python Forensics offers many never-before-published confirmed forensic modules, libraries, and suggestions that may be used correct out of the field. additionally, particular guide and documentation supplied with the code samples will permit even beginner Python programmers so as to add their very own targeted twists or use the versions offered to construct new ideas.
Already comprehend Python yet are looking to research extra? much more? Dive right into a number of themes utilized in perform for real-world purposes. Covers average expressions, Internet/network programming, GUIs, SQL/databases/ORMs, threading, and net improvement. find out about modern improvement developments resembling Google+, Twitter, MongoDB, OAuth, Python three migration, and Java/Jython.
Word: you're paying for a standalone product; MyProgrammingLab doesn't come packaged with this content material. if you'd like to buy either the actual textual content and MyProgrammingLab look for ISBN-10: 0133862259/ISBN-13: 978013386225 . That package deal comprises ISBN-10: 0133582736/ISBN-13: 9780133582734 and ISBN-10: 0133759113 /ISBN-13: 9780133759112.
Extra info for The Python Standard Library by Example
Dirname(__file__), '/', '. /broken_link', ] for dossier in FILENAMES: print 'File :', dossier print 'Absolute :', os. course. isabs(file) print 'Is dossier? :', os. course. isfile(file) print 'Is Dir? :', os. course. isdir(file) print 'Is hyperlink? :', os. direction. islink(file) print 'Mountpoint? :', os. course. ismount(file) print 'Exists? :', os. direction. exists(file) print 'Link Exists? :', os. course. lexists(file) print All try out services go back Boolean values. $ ln -s /does/not/exist broken_link $ python ospath_tests. py dossier : ospath_tests.
Import readline import logging LOG_FILENAME = '/tmp/completer. log' logging. basicConfig(filename=LOG_FILENAME, level=logging. DEBUG, ) category BufferAwareCompleter(object): def __init__(self, options): self. techniques = recommendations self. current_candidates =  go back def complete(self, textual content, state): reaction = None if country == zero: # this is often the 1st time for this article, # so construct a fit record. origline = readline. get_line_buffer() commence = readline. get_begidx() finish = readline. get_endidx() being_completed = origline[begin:end] phrases = origline.
Sort] print >>sys. stderr, 'Protocol:', protocols[sock. proto] print >>sys. stderr test: # ship information message = 'This is the message. will probably be repeated. ' print >>sys. stderr, 'sending "%s"' % message sock. sendall(message) amount_received = zero amount_expected = len(message) whereas amount_received < amount_expected: info = sock. recv(16) amount_received += len(data) print >>sys. stderr, 'received "%s"' % info ultimately: print >>sys. stderr, 'closing socket' sock. close() create_connection() makes use of getaddrinfo() to discover candidate connection parameters and returns a socket opened with the 1st configuration that creates a winning connection.
Po dossier, assemble the textual content dossier to the binary catalog structure utilizing msgfmt. The binary structure is utilized by the runtime catalog look up code. Load and turn on the perfect message catalog at runtime. the ultimate step is so as to add a number of traces to the applying to configure and cargo the message catalog and set up the interpretation functionality. There are a few how one can do this, with linked trade-offs. the remainder of this part will study these steps in a bit extra element, beginning with the code alterations wanted.
Python locale_atof_example. py united states: 1,234. fifty six => 1234. 560000 France: 1234,56 => 1234. 560000 Spain: 1234,56 => 1234. 560000 Portugal: 1234. fifty six => 1234. 560000 Poland: 1 234,56 => 1234. 560000 15. 2. five Dates and occasions one other very important point of localization is date and time formatting. import locale import time sample_locales = [ ('USA', 'en_US'), ('France', 'fr_FR'), ('Spain', 'es_ES'), ('Portugal', 'pt_PT'), ('Poland', 'pl_PL'), ] for identify, loc in sample_locales: locale. setlocale(locale.