L

L character, on long integers, 27

l(ist) debugger command, pdb module, 188

lambda operator, 48, 112

alternatives to, 274-275

LambdaType type, 237

last_accepted attribute, of Listener objects, 434

last_traceback variable, sys module, 231

last_type variable, sys module, 231

last_value variable, sys module, 231

lastChild attribute, of DOM Node objects, 570

lastgroup attribute, of MatchObject objects, 286

lastindex attribute, of MatchObject objects, 286

latin-1 encoding, description of, 169

launching a web browser, 544

launching python applications, 176

launching subprocesses, 402

examples, 404

lazy evaluation, 99

lchflags() function, os module, 387

lchmod() function, os module, 387

lchown() function, os module, 387

ldexp() function, math module, 252

le() function, operator module, 274

__le__() method, 56

leading 0b on integers, binary, 27

leading 0o on integers, octal, 27

leading 0x on integers, hexadecimal, 27

leading b character on string literals, byte strings, 29

leading r character on strings, raw strings, 29

leading u character on string literals, Unicode strings, 28

left shift operator <

left_list attribute, of dircmp objects, 315

left_only attribute, of dircmp objects, 315

legacy code, and exec statement, 115

len() function, 58, 206

on dicts, 74

on mappings, 44-45

on sequences, 39-40, 67, 69

on sets, 46, 75

__len__() method, 56, 58

and truth testing, 56

length attribute, of HTTPResponse objects, 504

less than operator

less than or equal to operator <=, 66

letters variable, string module, 287

levelname attribute, of Record objects, 359

levelno attribute, of Record objects, 359

lexical scoping, 97

lexicographical ordering

of UTF-8, 170

of strings, 70

lexists() function, os.path module, 397

LifoQueue() function, queue module, 444

limit_denominator() method, of Fraction objects, 250

limiting the output of error tracebacks, 232

line continuation character , 9, 25, 29

line continuation, and parentheses, braces, or brackets, 25

line separator character for files, 379

line structure of programs, 25

line_buffering attribute, of TextIOWrapper objects, 353

linecache module, 585

lineno attribute, of Record objects, 359

linesep variable, os module, 379

link() function, os module, 387

linkname attribute, of TarInfo objects, 322

Linux, 331

Linux link-level packet protocol, 470

address format, 472

Linux, epoll interface, 460

list comprehensions, 13

and declarative programming, 110

conditional expressions, 79

creation of tuples within, 109

difference from generator expression, 110

general syntax of, 108

scope of iteration variable, 109

similiarity to SQL queries, 111

similiarity to awk command, 111

list of Unix signal names, 400

list type, 38

list() function, 12, 40, 77, 207

applied to dictionaries, 16

list() method

of Manager objects, 429

of TarFile objects, 321

list_dialects() function, csv module, 551

listdir() function

Python 3, 630, 633

os module, 387

listen() method

of dispatcher objects, 456

of socket objects, 483

Listener class, multiprocessing module, 433

lists, 12, 40

appending to, 12, 40

as sequence, 39

compared to array objects, 260

comparison of, 70

concatenation, 12

counting items, 40

deletion of items, 69

empty, 12

equality of, 78

indexing operator, 12

inefficiency of insert(), 194

inserting items, 12, 40, 69

item assignment, 12, 69

keeping in sorted order, 261

list comprehension, 108

making shallow copy of, 40

nested, 13

random shuffling, 254

reassigning a slice, 12

removing items, 40

reversing, 40

searching, 40

shared by multiple processes, 429

slice assignment, 69

slice deletion, 69

slices, 12

sorting, 40

versus deque, 194, 262

versus tuples, 14

little endian format, 167

little endian, packing and unpacking, 292

ljust() method, of strings, 43

ln() method, of Decimal objects, 243

load() function

json module, 565

marshal module, 226

pickle module, 171, 227

load() method

of SimpleCookie objects, 512

of Unpickler objects, 228

loads() function

json module, 565

marshal module, 226

pickle module, 227

xmlrpc.client module, 526

local storage for threads, 443

local variables, 96

and eval(), 115

storage of in stack frames, 52

use before defined, 98

local() function, threading module, 443

localcontext() function, decimal module, 248

locale module, 587

locale setting, and string comparison, 70

localName attribute, of DOM Node objects, 570

locals() function, 207

localtime() function, time module, 406

Lock object

multiprocessing module, 427

threading module, 438

Lock() method, of Manager objects, 429

LOCK_* constants, flock() function, 348

lockf() function, fcntl module, 348

locking() function, msvcrt module, 373

locking

avoiding deadlock, 442

files on Windows, 373

multiprocessing module, 427

of critical sections, 414

of files, 348

threading module, 439

locks

and context managers, 89

and exceptions, 23

proper management of, 442

log files, real-time monitoring example, 19

log() function, math module, 252

log() method, of Logger objects, 358

log10() function, math module, 252

log10() method, of Decimal objects, 243

log1p() function, math module, 252

log_error() method, of BaseHTTPRequestHandler objects, 510

log_message() method, of BaseHTTPRequestHandler objects, 510

log_request() method, of BaseHTTPRequestHandler objects, 510

LogAdapter() function, logging module, 366

logging module, 355

adding extra fields to log messages, 365

and multiprocessing module, 435

basic configuration, 355

configuring with .ini files, 368

filtering messages, 359

formatting of messages, 365

handler objects, 362

how to configure, 367

including exceptions in log messages, 358

issuing log messages, 356

logger hierarchy, 360

message handling, 361

message propagation, 360

picking logger names, 356

using a null logger, 369

login() method

of FTP objects, 498

of SMTP objects, 514

lognormvariate() function, random module, 255

long integers, 27

and integers, 38

automatic promotion from integers, 27

long type, 38

long() function, 207

__long__() method, 61-62

lookup table, and dictionaries, 16

lookup() function

codecs module, 277

unicodedata module, 296

LookupError exception, 87, 212

loop() function, asyncore module, 457

looping, 17, 82

breaking out prematurely, 83

keeping a loop counter, 83

while statement, 8

loose-coupling of objects, 122

low-level file manipulation, 382

lower() method, of strings, 43

lowercase variable, string module, 287

lseek() function, os module, 383

lshift() function, operator module, 274

__lshift__() method, 60

lstat() function, os module, 387

lstrip() method, of strings, 43

lt() function, operator module, 274

__lt__() method, 56

LWPCookieJar class, http.cookiejar module, 513

M

-m command line option, 173-174

-m pdb option to interpreter, 189

mailbox module, 587

mailcap module, 587

main program execution, 146

main program, and pickle module, 228

main thread, 413

__main__ module, 146, 174

main() function, unittest module, 184

__main__, check needed for multiprocessing module, 417

major() function, os module, 387

make_server() function, wsgiref.simple_server module, 542

makedev() function, os module, 387

makedirs() function, os module, 387

makefile() method, of socket objects, 483

maketrans() function, string module, 290

making timing measurements, 191

managed objects, multiprocessing module, 428

Manager() function, multiprocessing module, 428

mant_dig attribute, of sys.float_info, 231

map() function, 207

and Python 3, 207

and optimization, 197

future_builtins module, 217

map() method, of Pool objects, 424

map-reduce, multiprocessing module, 424

map_async() method, of Pool objects, 425

Mapping abstract base class, 266

mappings, 44

deletion of items, 45

key index operator, 44

special methods of, 58

MappingView abstract base class, 266

marshal module, 226

match() function, re module, 284

match() method, of Regex objects, 285

MatchObject objects, re module, 285

math module, 251

mathematical operators

in-place, 61

mixed types, 66-67

mathematical special methods, 60

max attribute

of date class, 337

of datetime class, 340

of sys.float_info, 231

of time class, 338

of timedelta class, 341

max() function, 13, 39-40, 67, 69, 207

on sets, 75

required methods for user-defined objects, 57

max_10_exp attribute, of sys.float_info, 231

max_exp attribute, of sys.float_info, 231

maxint variable, sys module, 231

maxsize variable, sys module, 231

maxunicode variable, sys module, 231

md5() function, hashlib module, 559

MemberDescriptorType type, 237

membership test

of dicts, 16, 74

of sequences, 67

memmove() function, ctypes module, 617

memoization of results, 242

memory efficiency

and __slots__, 133

of generator expressions, 110

of generators, 107

memory management, 128

checking for leaks, 221

creation of instances, 129

garbage collection, 35, 220

reference counting, 129

memory mapped files, 370

and IPC, 413

memory use

array objects, 260

measuring, 192

obtaining size of objects, 234

tuples versus lists, 14

memory, location of objects, 33

MemoryError exception, 87, 214

MemoryHandler class, logging module, 362

memset() function, ctypes module, 617

merge() function, heapq module, 270

Mersenne Twister, 254

Message class, email package, 552, 555

message attribute, of Exception objects, 213

message digests, 559

message passing, 414-415

and coroutines, 415

and synchronization, 415

coroutines, 108

definition of, 413

sending byte buffers, 421

sending objects between processes, 421

message propagation, of log messages, 360

message queues, 415

coroutines, 108

multiprocessing module, 418

message_from_file() function, email package, 552

message_from_string() function, email package, 552

metaclass keyword argument, of class definitions, 139

__metaclass__ attribute, of classes, 139

__metaclass__ global variable, 139

metaclasses, 138

__prepare__() method, 627-628

and descriptors, 140

and inheritance, 139

caution on use, 141

example of, 140

how to define, 139

performance benefits, 197

use of __new__() method, 55, 129

use of a custom dictionary object, 628

method resolution order, and TypeError exception, 122

method resolution

__mro__ attribute, 121

multiple inheritance, 121

single inheritance, 120

methodcaller() function, operator module, 275

methodHelp() method, of ServerProxy objects, 525

methods, 48, 117

bound, 49, 125

calling process, 48

class, 125

@classmethod decorator, 48

defining in classes, 21

definition of, 118

handling as properties, 125

preventing redefinition in subclasses, 128

static, 125

@staticmethod decorator, 48

type of, 47

type of built-in, 49

unbound, 49

use of super() function, 120

methodSignatures() method, of ServerProxy objects, 525

MethodType type, 47-48, 237

microsecond attribute, of time objects, 338

microthreading, 446

migrating code

Python 2 to 3, 634

practical strategy, 637

MIMEApplication class, email package, 557

MIMEAudio class, email package, 557

MIMEImage class, email package, 557

MIMEMessage class, email package, 557

MIMEMultipart class, email package, 557

MIMEText class, email package, 558

mimetypes module, 566

min attribute

of date class, 337

of datetime class, 340

of sys.float_info, 231

of time class, 338

of timedelta class, 341

min() function, 13, 39-40, 67, 69, 207

on sets, 75

required methods for user-defined objects, 57

min_10_exp attribute, of sys.float_info, 231

min_exp attribute, of sys.float_info, 231

minimum requirements for supporting equality, 57

minor() function, os module, 387

minute attribute, of time objects, 338

mirrored() function, unicodedata module, 296

missing parenthesese, and tuples, 14

mixed-type mathematical operations, 66-67

mixin classes, 122

mixing byte strings and Unicode, 167

mkd() method, of FTP objects, 498

mkdir() function, os module, 388

mkdtemp() function, tempfile module, 323

mkfifo() function, os module, 388

mknod() function, os module, 388

mkstemp() function, tempfile module, 323

mktemp() function, tempfile module, 323

mktime() function, time module, 406

mmap module, 369

mmap() function, mmap module, 370

mod() function, operator module, 273

__mod__() method, 60

mode attribute

of FileIO objects, 350

of TarInfo objects, 322

of files, 161

modf() function, math module, 252

modifying global variables from a function, 18

modifying the module search path, 147

module attribute, of Record objects, 359

module loading, 147

module reloading, 149

module search path

and site module, 177

and zip files, 147

modifying, 147

setting with environment variable, 174

module unloading, 149

__module__ attribute, of types, 50

modulefinder module, 585

modules variable, sys module, 149, 231

modules, 23, 143

accessing classes, 144

and .pyc files, 148

as objects, 144

attribute access, 51

attributes of, 51

dynamic loading, 144

global namespace for functions, 96

importing multiple, 144

one-time execution, 144

search path of, 147

self-testing with doctest, 182

type of, 50

type of module object, 47

types of recognized files, 148

using to write extensible programs, 144

ModuleType type, 47, 237

modulo operator %, 65

month attribute, of date objects, 337

Morsel class, http.cookies module, 512

move() function, shutil module, 319

move() method, of mmap objects, 371

moving the file pointer, 161

MozillaCookieJar class, http.cookiejar module, 513

__mro__ attribute, of classes, 121

MSG_* constants, socket module, 483

msvcrt module, 372

mtime attribute, of TarInfo objects, 322

mul() function, operator module, 273

__mul__() method, 60

multi-dimensional lists, 13

MultiCall() function, xmlrpc.client module, 526

multicore, and program execution, 414

multiple inheritance, 120-121

multiple statements on the same line, 26

multiplexing, of I/O, 459

multiplication operator *, 65

multiprocessing module, 415

and global interpreter lock, 444

and pickle, 435

connecting separate processes, 433

distributed computing, 435

logging, 435

managed objects, 428

passing a list through shared memory, 427

pipes, 421

process pools, 424

queues, 418

shared memory, 426

synchronization primitives, 427

use of __main__ check, 417

multithreaded chicken, 414

mutability

default function arguments, 94

dictionary keys, 44

function parameters, 95

in-place assignment operators, 75

reference counting, 35

mutable, definition of, 33

MutableMapping abstract base class, 266

MutableSequence abstract base class, 266

MutableSet abstract base class, 266

mutual exclusion lock, 438

MySQL, accesing from Python, 297

N

N escape code, in strings, 28

n(ext) debugger command, pdb module, 189

name attribute

of FieldStorage objects, 535

of FileIO objects, 350

of Process objects, 417

of Record objects, 359

of TarInfo objects, 322

of Thread objects, 436

of files, 161

name mangling, of private attributes, 127

name variable, os module, 379

__name__ attribute

of built-in functions, 49

of functions, 48

of methods, 49

of modules, 51

of types, 50

__name__ variable, of modules, 146

name() function, unicodedata module, 296

named tuples

use as tuples, 264

use by standard library, 265

NamedTemporaryFile() function, tempfile module, 324

namedtuple() function, collections module, 264

NameError exception, 87, 214

NameError exception in __del__ ignored, 179

NameError exception, and variable lookup, 96

namelist() method, of ZipFile objects, 326

Namespace() method, of Manager objects, 429

namespace

and classes, 117

and import statement, 24, 143

local variables of function, 96

namespaceURI attribute, of DOM Node objects, 570

NaN variable, decimal module, 248

NaN

not a number, 213

not a number, decimal module, 244

ne() function, operator module, 274

__ne__() method, 57

neg() function, operator module, 273

__neg__() method, 61

negative indices, 68-69

negInf variable, decimal module, 248

nested classes, problem with pickle, 228

nested functions, 97

and closures, 99

nested lists, 13

nested() function, contextlib module, 267

Netlink protocol, 470

address format, 472

netloc attribute

of urlparse objects, 520

of urlsplit objects, 521

netrc module, 587

network programming modules, Python 3 reorganization, 497

network programming

Unicode encoding, 452

asynchronous, 467

event-driven programming, 455

getting hostname, 474

introduction, 449

performance of polling, 468

new() function

hashlib module, 559

hmac module, 559

__new__() method, 54-55

and instance creation, 129

and metaclasses, 139

caution when reading code, 129

use by immutable types, 129

uses of, 55

newline character, difference on Unix/Windows, 159

newline escape code in strings, 28

newline parameter, to open() function, 159

newline suppression, print statement, 162

newline termination of statements, 7

newlines attribute

of TextIOWrapper objects, 353

of files, 161

next() function, 207

next() method, 59

of TarFile objects, 321

of files, 160

of generators, 19, 53, 103

of iterators, 82

use with coroutines, 104

__next__() method, 59

Python 3, 633

of generators, 19, 103

of iterators, 82

nextset() method, of Cursor objects, 299

nextSibling attribute, of DOM Node objects, 570

NI_* constants, socket module, 475

nice() function, os module, 392

nis module, 586

nlargest() function, heapq module, 270

nntplib module, 587

no_site attribute, of sys.flags, 230

nodeName attribute, of DOM Node objects, 570

nodeType attribute, of DOM Node objects, 570

nodeValue attribute, of DOM Node objects, 570

non-printing characters, specifying in string literals, 28

None, 38

and default arguments, 94

return statement in functions, 96

nonlocal statement, Python 3, 97, 624

normalization of Unicode strings, 171

normalize() function, unicodedata module, 171, 296

normalize() method, of DOM Node objects, 571

normalvariate() function, random module, 255

normcase() function, os.path module, 398

normpath() function, os.path module, 398

not equal to operator !=, 66

not operator, boolean expressions, 9, 77

not_() function, operator module, 274

NotConnected exception, http.client module, 504

notify() method, of Condition objects, 441

notify_all() method, of Condition objects, 441

NotImplementedError exception, 87, 214

NotSupportedError exception, database API, 302

now() method, of datetime class, 339

nsmallest() function, heapq module, 270

NTEventLogHandler class, logging module, 362

ntohl() function, socket module, 476

ntohs() function, socket module, 476

ntransfercmd() method, of FTP objects, 498

null object, 369

null values, 38

NULL-terminated strings, and UTF-8, 170

Number abstract base class, 253

number of CPUs on system, 434

numbers module, 138, 252

numbers, example of defining new type, 133

numerator attribute

of Fraction objects, 250

of integers, 39

numeric data, and strings, 11

numeric literals, 26-27

numeric type coercision, 66-67

numeric type hierarchy, 137, 253

numeric types, 38

numeric() function, unicodedata module, 296

numpy extension, 39, 261

O

-O command line option, 91, 148, 173-174, 369

object, 47

object base class, 21, 119

object() function, 208

objects, 21

attributes of, 33

class of, 34

comparison, 34

comparison in Python 3, 633

container or collection, 33

defining a null object, 369

definition of, 33

first-class status, 36

getting a list of referrers, 221

getting the size of, 192

hierarchy of, 137

how to copy, 36

identity of, 33

inspecting with dir(), 63

instance of, 33

introspection of, 222

methods for comparison, 56

name of, 35

obtaining size of, 234

persistence, 171

proxies in multiprocessing module, 431

reference counting of, 34

representation of, 131

requirements for ordering, 57

sending between processes with pipes, 421

sending between processes with queues, 418

serializing with marshal, 226

serializing with pickle, 227

sharing in the interpreter, 35

supporting iteration, 82

type of, 33

weak references to, 240

observer pattern, 130, 240

oct() function, 77, 208

future_builtins module, 217

octal integer literals, 27

octdigits variable, string module, 287

old-style classes, 139

-OO command line option, 148, 173-174

open() function, 10, 158, 208

Python 3, 159

codecs module, 167, 279

codecs module and Python 3, 279

dbm module, 310

description of file modes, 159

difference between Python 2 and 3, 208

gzip module, 317

io module, 354

os module, 384

shelve module, 171, 311

tarfile module, 319

webbrowser module, 544

open() method

of ZipFile objects, 326

of controller objects, 544

open_new() function, webbrowser module, 544

open_new() method, of controller objects, 544

open_new_tab() function, webbrowser module, 544

open_osfhandle() function, msvcrt module, 373

OpenKey() function, winreg module, 410

OpenKeyEx() function, winreg module, 410

openpty() function, os module, 385

OpenSSL, 486

example of creating certificates, 489

operating system, scheduling by, 414

OperationalError exception, database API, 302

operator module, 273

alternative to lambda, 274

use in optimization, 274

operator overloading, 54

example of, 133

order of operands, 134

reversed operands, 60

type coercion, 134

operators, 30, 65

mathematical, 60

precedence of, 78

optimization

__slots__ attribute of classes, 132, 196

array objects, 260

attribute binding, 195-196

built-in types, 194

creation of instances, 195

decorators and metaclasses, 197

definition of speedup, 192

deque objects, 263

dict() function, 195

dict lookups, 197

dicts versus classes, 195

disassembly, 193

effect of adding layers, 195

exceptions, 196-197

formatting of log messages, 358

functional programming, 197

impact of I/O polling, 469

internal type cache, 233

lists versus array objects, 260

logging module, 369

making timing measurements, 191

map() and filter() functions, 197

marshal versus pickle, 226

measuring memory use, 192

repeated timing measurements, 192

select() function, 467

sorting callback functions, 275

speedup, 194

tuning strategies, 194

use of io module, 354

use of multiprocessing pools, 426

use of operator module, 274

user defined classes, 195

optimize attribute, of sys.flags, 230

optimized mode, enabling with an environment variable, 174

optional function arguments, 18, 93

and None, 38

OptionParser() function, optparse module, 374

options() method, of ConfigParser objects, 333

optionxform() method, of ConfigParser objects, 333

optparse module, 374

example, 157

or operator, boolean expressions, 9, 77

or_() function, operator module, 274

__or__() method, 60

ord() function, 77, 208

order of evaluation, 78

attempts to modify, 79

order of operands, operator overloading, 134

organizing code for distribution, 152

OS X, 331

os module, 158, 378

os.environ variable, 158

os.path module, 396

OSError exception, 87, 214

ossaudiodev module, 588

output() method

of Morsel objects, 512

of SimpleCookie objects, 512

OutputString() method, of Morsel objects, 513

overflow, lack of with integers, 66

OverflowError exception, 214

P

p debugger command, pdb module, 189

P_* constants, spawnv() function, 392

pack() function, struct module, 290

pack() method, of Struct objects, 291

pack_into() function, struct module, 290

pack_into() method, of Struct objects, 291

packages, 149

relative import, 150-151

PACKET_* constants, socket module, 472

packing

binary data structures, 290

of tuples, 14

pairs, creating a list of from dictionary, 45

parallel iteration over sequences, 83

parameter passing to functions, 95

params attribute, of urlparse objects, 520

paramstyle variable, database API, 300

pardir variable, os module, 386

parent class, 119

parentNode attribute, of DOM Node objects, 570

paretovariate() function, random module, 256

parse() function

xml.dom.minidom module, 570

xml.etree.ElementTree module, 578

xml.sax module, 580

parse() method

of ElementTree objects, 574

of Formatter objects, 288

parse_args() method, of OptionParser objects, 158, 376

parse_header() function, cgi module, 536

parse_multipart() function, cgi module, 536

parse_qs() function, urllib.parse module, 521

parse_qsl() function, urllib.parse module, 522

parser module, 586

parseString() function

xml.dom.minidom module, 570

xml.sax module, 580

parsing

CSV files, 548

HTML, 561

URLs, 520

XML, 568

command line options, 157, 374

email messages, 552

form fields in CGI scripts, 534

large XML documents with ElementTree, 579

robots.txt file, 523

partial() function

functools module, 76, 268

use with network handlers, 510

partition() method, of strings, 41, 43

pass statement, 9, 25, 82

password attribute

of urlparse objects, 520

of urlsplit objects, 521

path attribute

of BaseHTTPRequestHandler objects, 509

of urlparse objects, 520

of urlsplit objects, 521

path variable

os module, 379

sys module, 147, 177, 232

__path__ attribute, of modules, 51

__path__ variable, in packages, 151

pathconf() function, os module, 388

pathname attribute, of Record objects, 359

pathsep variable, os module, 386

pattern attribute, of Regex objects, 284

pattern syntax, regular expressions, 281

pause() function, signal module, 399

pdb module, 186

debugging programs from command shell, 189

.pdbrc configuration file, 190

.pdbrc configuration file, 190

peek() method, of BufferReader objects, 351

PEM_cert_to_DER_cert() function, ssl module, 488

PEP 249, Python Database API Specification, 297

PEP 333 (WSGI), 540

per-user site directory, 154, 177

installing packages in, 178

performance

of binary file I/O, 351-352

of generator expressions, 110

of logging module, 369

of type checking, 34

Perl

and dynamic scope, 97

interpretation of numeric strings vs. Python, 11

permutations() function, itertools module, 272

persistent dictionary, shelve module, 171

PHP, interpretation of numeric strings vs. Python, 11

pi variable, math module, 252

pickle module, 171, 226

__main__ module, 228

and multiprocessing module, 435

cPickle, 229

incompatible objects, 171

interaction with copy module, 220

protocol selection, 171-172

security concerns, 172

used by shelve, 311

pickle protocol, selecting in shelve module, 172

Pickler class, pickle module, 228

pickletools module, 586

pid attribute

of Popen objects, 404

of Process objects, 417

Pipe() function, multiprocessing module, 421

pipe() function, os module, 385

pipelines and generators, 19

pipelines, and generators, 106-107

pipes module, 586

pipes, creating with subprocess module, 403

pkgutil module, 586

placement of decorators, 101

platform module, 586

platform variable, sys module, 232

plistlib module, 587

plock() function, os module, 392

pm() function, pdb module, 186

POINTER() function, ctypes module, 614

pointer() function, ctypes module, 615

poll() function, select module, 459

poll() method

of Connection objects, 421

of Poll objects, 460

of Popen objects, 403

POLL* constants, select module, 459

polling, 459

performance of, 468-469

polymorphism, 122

Pool() function, multiprocessing module, 424

pop() method

of array objects, 260

of deque objects, 262

of dicts, 45, 95

of lists, 41

of sets, 47

Popen() function, subprocess module, 402

popen() function, os module, 392

popitem() method, of dicts, 45

popleft() method, of deque objects, 262

poplib module, 587

port attribute

of urlparse objects, 520

of urlsplit objects, 521

port number

in network programs, 449

list of well known, 450

portability, of marshal module, 226

portable manipulation of filenames, 396

pos attribute, of MatchObject objects, 286

pos() function, operator module, 273

__pos__() method, 61

POSIX interface, 331

posix attribute, of TarFile objects, 321

post_mortem() function, pdb module, 186

pow() function, 66, 208

math module, 252

__pow__() method, 60

power operator **, 65

pp debugger command, pdb module, 189

pprint module, 586

preamble attribute, of Message objects, 554

prec attribute, of Context objects, 247

precision, of floating point, 38

predicate() function, itertools module, 271

prefix attribute, of DOM Node objects, 570

—prefix option to setup.py, 154

prefix variable, sys module, 177, 232

__prepare__() method, Python 3 metaclasses, 627-628

preventing the creation of .pyc files, 230

previousSibling attribute, of DOM Node objects, 570

print statement, 6, 162

and __str__(), 56

and sys.stdout, 161

file redirection, 10, 163

formatted output, 8, 162

newline suppression, 162

softspace attribute of files, 162

syntax error with Python 3, 6

trailing comma, 10

print() function, 163, 209

Python 3, 631

enabling in Python 2.6, 163

file redirection, 163

newline suppression, 163

separator character, 163

print_directory() function, cgi module, 537

print_environ() function, cgi module, 537

print_environ_usage() function, cgi module, 537

print_exc() function, traceback module, 236

print_exception() function, traceback module, 236

print_form() function, cgi module, 537

print_last() function, traceback module, 236

print_stack() function, traceback module, 236

print_tb() function, traceback module, 235-236

printable variable, string module, 287

printdir() method, of ZipFile objects, 326

printf() function equivalent, 8

printing to the screen, 10

printing

creating custom formatters, 288

dates and times, 406

formatted, 8

priority queue, 269

PriorityQueue() function, queue module, 445

private attributes, 127

and properties, 128

name mangling of, 127

private class members, 26

private methods, and inheritance, 128

private specifier, lack of, 127

probability, random number distributions, 255

process attribute, of Record objects, 359

process id, getting, 380

Process() function, multiprocessing module, 416

processes

connecting with pipes, 421

daemonic, 415

definition of, 413

joining, 415

scheduling of, 414

sending signals to, 392

terminating, 392, 403-404, 415

worker pools, 424

ProcessingInstruction() function, xml.etree.ElementTree module, 575

processingInstruction() method, of ContentHandler objects, 581

producer-consumer

with coroutines, 20

with pipes, 422

with queues, 419

with threads and condition variables, 441

with threads and semaphores, 439

product() function, itertools module, 272

profile module, 190

profiling, 190

interpreting output, 191

program execution model, 81

program execution, main program, 146

program structure, 81

program termination, 7, 179, 233

and garbage collection, 179

brutal, 179

brute force, 391

ignored NameError exception, 179

registering cleanup functions, 219

programming errors, lack of compiler checking, 181

ProgrammingError exception, database API, 302

prompts

changing, 176

interactive mode, 175

propagate attribute, of Logger objects, 360

properties, 117

and __setattr_() method, 131

and private attributes, 128

definition of, 124

set and delete functions, 126

uniform access principle, 125

use by methods, 125

@property decorator, 124

property() function, 126, 209

protected specifier, lack of, 127

proto attribute, of socket objects, 484

protocol parameter, to pickle functions, 171

protocol_version attribute, of BaseHTTPRequestHandler class, 509

ProtocolError exception, xmlrpc.client module, 527

proxies, and attribute binding methods, 132

proxy, 62

proxy functions, 95

proxy objects

and multiprocessing module, 428, 431

problem with type checking, 135

proxy() function, weakref module, 241

ProxyBasicAuthHandler class, urllib.request module, 518-519

ProxyDigestAuthHandler class, urllib.request module, 518-519

ProxyHandler class, urllib.request module, 518-519

ProxyTypes class, weakref module, 241

ps1 variable, sys module, 232

ps2 variable, sys module, 232

.pth files, site configuration, 177

pty module, 586

punctuation variable, string module, 287

push() method, of asynchat objects, 453

push_with_producer() method, of asynchat objects, 453

put() method, of Queue objects, 418, 445

put_nowait() method, of Queue objects, 419, 445

putch() function, msvcrt module, 373

putenv() function, os module, 380

putheader() method, of HTTPConnection objects, 503

putrequest() method, of HTTPConnection objects, 503

putwch() function, msvcrt module, 373

pwd module, 586

pwd() method, of FTP objects, 498

.py files, 6, 147

and library modules, 23

py2app package, 154

py2exe package, 154

py3k_warning attribute, of sys.flags, 230

py3kwarning variable, sys module, 232

Py_BEGIN_ALLOW_THREADS macro, 607

Py_BuildValue() function, 602

py_compile module, 586

Py_DECREF() macro, 607

Py_END_ALLOW_THREADS macro, 607

Py_Finalize() function, 609

Py_GetExecPrefix() function, 609

Py_GetPath() function, 609

Py_GetPrefix() function, 609

Py_GetProgramFullPath() function, 609

Py_INCREF() macro, 607

Py_Initialize() function, 609

Py_IsInitialized() function, 609

Py_SetProgramName() function, 609

Py_XDECREF() macro, 607

Py_XINCREF() macro, 607

PyArg_ParseTuple() function, 597

PyArg_ParseTupleAndKeywords() function, 597

PyBytes_AsString() function, 611

.pyc files, 147

compilation on import, 148

preventing the creation of, 230

when created, 148

pyclbr module, 586

.pyd files, compiled extensions, 148

pydev, 5

pydoc command, 24

PyErr_Clear() function, 606

PyErr_ExceptionMatches() function, 606

PyErr_NoMemory() function, 605

PyErr_Occurred() function, 606

PyErr_SetFromErrno() function, 605

PyErr_SetFromErrnoWithFilename() function, 605

PyErr_SetObject() function, 605

PyErr_SetString() function, 605

PyEval_CallObject() function, 610

PyEval_CallObjectWithKeywords() function, 610

PyExc_* exceptions, in extension modules, 605

PyFloat_AsDouble() function, 611

PyImport_ImportModule() function, 610

PyInt_AsLong() function, 611

PyLong_AsLong() function, 611

PyModule_AddIntConstant() function, 604

PyModule_AddIntMacro() function, 605

PyModule_AddObject() function, 604

PyModule_AddStringConstant() function, 604

PyModule_AddStringMacro() function, 605

.pyo files, 147

when created, 148

PyObject_GetAttrString() function, 610

PyObject_SetAttrString() function, 610

pypi (Python Package Index), 154

pyprocessing library, 435

PyRun_AnyFile() function, 608

PyRun_InteractiveLoop() function, 609

PyRun_InteractiveOne() function, 609

PyRun_SimpleFile() function, 609

PyRun_SimpleString() function, 609

PyString_AsString() function, 611

PySys_SetArgv() function, 610

Python 3

2to3 tool, 635-637

Ellipsis as an expression, 626

I/O system, 349, 631

Unicode characters in identifiers, 622

__next__() method, 633

absolute imports, 634

abstract base class, 137

adoption of, 621

and WSGI, 541

byte strings and system interfaces, 630

chained exceptions, 626

command line options, 633

commands module, 332

comparison, 633

dictionary comprehension, 623

dictionary operations, 45

difference in extension modules, 595

different behavior of byte strings, 629

division operator, 65

encode() and encode() methods, 629

environment variables, 633

exception attributes, 213

exec() function, 631

extended iterable unpacking, 623

filenames, 633

files, 160

filter() function, 205

function annotations, 624

generator changes, 103

import statement, 151

incompatibility with Python 2, 621

integer division, 633

interactive mode encoding issues, 175

iterator protocol, 633

keyword-only arguments, 625

map() function, 207

metaclasses, 139, 627-628

migration pitfalls, 629

network programming, 452

next() method of generators, 53

nonlocal statement, 624

open() function, 159, 208, 279

practical porting strategy, 637

print() function, 209, 631

raw_input() function, 209

reorganization of network modules, 497

round() function, 209

set comprehension, 623

set literals, 622

socketserver module, 489

standard library reorganization, 634

super() function, 120, 210, 627

supporting both Python 2 and 3, 638

syntax error with print, 6

third party libraries, 621

types module, 237

unbound methods, 49

unicode() function removal, 211

using new built-in functions in Python 2, 217

view objects on dicts, 632

viewing objects in ASCII, 201

who should use, 621

xrange() and range() functions, 17

xrange() function removal, 44, 211

zip() function, 83, 211

python interpreter, 6

PYTHON* environment variables, 174

Python.h header file, in extensions, 594

.pyw files, 147, 176

PyZipFile() function, zipfile module, 325

Q

-Q command line option, 173

q(uit) debugger command, pdb module, 189

qsize() method, of Queue objects, 419, 445

queries, how to safely form for databases, 300

query attribute

of urlparse objects, 520

of urlsplit objects, 521

QueryInfoKey() function, winreg module, 410

QueryValue() function, winreg module, 410

QueryValueEx() function, winreg module, 410

queue module, 444

Queue() function

multiprocessing module, 418

queue module, 444

Queue() method, of Manager objects, 429

queue, circular, 262

queues

coroutines, 108

example with threads, 446

message passing, 415

multiple consumers and producers, 420

priority, 269

shared by multiple processes, 429

thread programming, 444

quit() method

of FTP objects, 498

of SMTP objects, 514

quitting the interactive interpreter, 7

quopri module, 567

quote() function, urllib.parse module, 522

quote_from_bytes() function, urllib.parse module, 522

quote_plus() function, urllib.parse module, 522

quoteattr() function, xml.sax.saxutils module, 583

quotes, difference between styles, 27

quoting, characters in URLs, 522

R

!r specifier in string formatting, 74

r character, before a string literal, 29

‘r’ mode, to open() function, 159

r(eturn) debugger command, pdb module, 189

race condition, 193, 414

__radd__() method, 60

when invoked over __add__(), 134

radians() function, math module, 251

radix attribute, of sys.float_info, 231

raise statement, 23, 84-85, 88

__rand__() method, 61

RAND_add() function, ssl module, 488

RAND_egd() function, ssl module, 488

RAND_status() function, ssl module, 488

randint() function, random module, 254

random module, 254

random numbers, and threads, 256

random() function, random module, 255

randrange() function, random module, 254

range of integer values, 38

range() function, 17, 209

removal in Python 3, 17

Rational abstract base class, 253

rational numbers, 250

raw I/O on files, 350

raw socket, 470

raw strings, 29

Unicode, 29

backslash rules, 29

use in regular expressions, 281

raw-unicode-escape encoding, description of, 170

raw_decode() method, of JSONDecoder objects, 566

raw_input() function, 10, 162, 209

Python 3, 11, 209

RawArray() function, multiprocessing module, 427

RawConfigParser class, configparser module, 336

RawIOBase abstract base class, 354

RawValue() function, multiprocessing module, 426

RCVALL_* constants, socket module, 482

__rdiv__() method, 60

__rdivmod__() method, 60

re attribute, of MatchObject objects, 286

re module, 41, 69, 281

read() function, os module, 385

read() method

of BufferReader objects, 351

of ConfigParser objects, 333

of FileIO objects, 350

of HTTPResponse objects, 504

of StreamReder objects, 278

of TextIOWrapper objects, 353

of ZipFile objects, 326

of files, 159-160

of mmap objects, 371

of ssl objects, 488

of urlopen objects, 515

read-eval loop, 5

read1() method, of BufferReader objects, 351

read_byte() method, of mmap objects, 371

read_mime_types() function, mimetypes module, 567

readable() method

of IOBase objects, 349

of dispatcher objects, 456

readall() method, of FileIO objects, 350

reader() function, csv module, 549

ReadError exception, tarfile module, 322

readfp() method, of ConfigParser objects, 334

reading CSV data, example of, 14

reading configuration files, 332

reading lines, files, 10

reading user input, 10, 162

readinto() method, of BufferReader objects, 351

readline library, 176

readline module, 586

readline() method

of IOBase objects, 349

of StreamReder objects, 278

of TextIOWrapper objects, 353

of files, 10, 159-160

of mmap objects, 371

of urlopen objects, 515

readlines() method

of IOBase objects, 349

of StreamReder objects, 278

of files, 13, 159-160

of urlopen objects, 515

readlink() function, os module, 388

ready() method, of AsyncResult objects, 425

Real abstract base class, 253

real attribute

of complex numbers, 39

of floating point, 39

realpath() function, os.path module, 398

reason attribute, of HTTPResponse objects, 504

reassigning part of a list, 12

Record objects, logging module, 359

recursion limit, changing, 112, 235

recursion, 112

and decorators, 102, 113

and generator functions, 112

recursive traversal of directory trees, 390

recv() method

of Connection objects, 421

of dispatcher objects, 456

of socket objects, 483

recv_bytes() method, of Connection objects, 421

recv_bytes_into() method, of Connection objects, 422

recv_into() method, of socket objects, 483

recvfrom() method, of socket objects, 483

recvfrom_info() method, of socket objects, 483

recvmsg() system call, lack of support, 486

reduce() function, functools module, 268

__reduce__() method, 229

__reduce_ex__() method, 229

reentrant mutex lock, 438

ref() function, weakref module, 240

reference counting, 34, 129

and copying, 35

and del statement, 35

and memory use, 192

and mutable objects, 36

in extension modules, 607

obtaining, 35

reference cycles

and garbage collection, 221

avoiding with weak references, 130, 240

ReferenceError exception, 87, 214

REG_* constants, winreg module, 409

Regex objects, re module, 284

register command of setup.py file, 155

register() function

atexit module, 179, 219

webbrowser module, 544

register() method

of BaseManager class, 430

of Poll objects, 459

of abstract base classes, 137

register_adapter() function, sqlite3 module, 305

register_converter() function, sqlite3 module, 304

register_dialect() function, csv module, 551

register_function() method, of XMLRPCServer objects, 527

register_instance() method, of XMLRPCServer objects, 527

register_introspection_functions() method, of XMLRPCServer objects, 528

register_multicall_functions() method, of XMLRPCServer objects, 528

RegLoadKey() function, winreg module, 409

regular expressions

pattern syntax, 281

re module, 281

use of raw strings, 281

relational databases, accessing from Python, 297

relational operators, 9, 56

relative package imports, 150-151

release() method

of Condition objects, 441

of Lock objects, 438

of RLock objects, 439

of Semaphore objects, 439

reliable datagrams, 470

reload() function, 149

reloading modules, 149

relpath() function, os.path module, 398

remote procedure call

XML-RPC, 524

multiprocessing module, 423-424

remove() function, os module, 388

remove() method

of Element objects, 577

of array objects, 260

of deque objects, 262

of lists, 40-41

of sets, 15, 47

remove_option() method, of ConfigParser objects, 334

remove_section() method, of ConfigParser objects, 334

removeChild() method, of DOM Node objects, 571

removedirs() function, os module, 388

removeFilter() method

of Handler objects, 364

of Logger objects, 359

removeHandler() method, of Logger objects, 361

removing directories, 318

removing files, 388

removing sequence items, 40

removing slices, 40

rename() function, os module, 388

rename() method, of FTP objects, 498

renames() function, os module, 388

repeat() function

cProfile module, 190

itertools module, 272

operator module, 274

timeit module, 192

‘replace’ error handling, Unicode encoding, 166

replace() method

of date objects, 337

of datetime objects, 340

of strings, 41, 43

of time objects, 338

replace_header() method, of Message objects, 556

replaceChild() method, of DOM Node objects, 571

replacing substrings, 41

replication, of sequences and shallow copies, 67

report() method, of dircmp objects, 315

report_full_closure() method, of dircmp objects, 315

report_partial_closure() method, of dircmp objects, 315

repr (reprlib) module, 586

repr() function, 11, 55, 77, 176, 209

and eval(), 55

difference from str(), 12

__repr__() method, 55-56

representing dates and times, 336

request attribute, of BaseRequestHandler objects, 490

Request() function, urllib.request module, 516

request() method, of HTTPConnection objects, 503

request_queue_size attribute, of SocketServer class, 492

request_version attribute, of BaseHTTPRequestHandler objects, 509

RequestHandlerClass attribute, of SocketServer objects, 492

reraising the last exception, 84

reserved attribute, of ZipInfo objects, 327

reserved words, 26

reset() method

of HTMLParser objects, 562

of IncrementalDecoder objects, 279

of IncrementalEncoder objects, 278

of StreamReder objects, 278

of StreamWriter objects, 278

resetwarnings() function, warnings module, 239

resize() function, ctypes module, 617

resize() method, of mmap objects, 371

resolution attribute

of date class, 337

of datetime class, 340

of time class, 338

of timedelta class, 341

resource module, 587

response time, asynchronous networking, 467

ResponseNotReady exception, http.client module, 504

responses attribute, of BaseHTTPRequestHandler class, 509

restricting attribute names, 132

restype attribute, of ctypes function objects, 613

result of last operation in interactive mode, 6, 176

retrbinary() method, of FTP objects, 499

retrlines() method, of FTP objects, 499

return statement, 96

returncode attribute, of Popen objects, 404

returning multiple values from a function, 18, 96

reverse keyword argument, to sort(), 40

reverse() method

of array objects, 260

of lists, 40-41

reversed operand methods, when invoked, 134

reversed operands, operator overloading, 60

reversed() function, 209

reversing a list, 40

rfile attribute

of BaseHTTPRequestHandler objects, 509

of StreamRequestHandler objects, 491

rfind() method, of strings, 41, 43

__rfloordiv__() method, 60

right shift operator >>, 65

right_list attribute, of dircmp objects, 315

right_only attribute, of dircmp objects, 315

rindex() method, of strings, 41, 43

rjust() method, of strings, 43

rlcompleter module, 586

rlecode_hqx() function, binascii module, 548

rledecode_hqx() function, binascii module, 548

RLock object

multiprocessing module, 427

threading module, 438

RLock() method, of Manager objects, 429

__rlshift__() method, 61

rmd() method, of FTP objects, 499

rmdir() function, os module, 388

__rmod__() method, 60

rmtree() function, shutil module, 319

__rmul__() method, 60

robotparser module, 523

robots.txt file, 523

rollback() method, of Connection objects, 298

rollover() method, of SpoolTemporaryFile objects, 324

root logger, logging module, 355

__ror__() method, 61

rotate() method, of deque objects, 263

rotating log files, 363

RotatingFileHandler class, logging module, 363

round() function, 66, 209

and Python 3, 209

rounding attribute, of Context objects, 247

rounding behavior, 66

change in Python 3, 66

rounding, decimal module, 245

rounds attribute, of sys.float_info, 231

row_factory attribute, of Connection objects, 308

rowcount attribute, of Cursor objects, 299

rpartition() method, of strings, 41

__rpow__() method, 61

__rrshift__() method, 61

rshift() function, operator module, 274

__rshift__() method, 60

rsplit() method, of strings, 41, 43

rstrip() method, of strings, 43

__rsub__() method, 60

__rtruediv__() method, 60

Ruby, differences in object system, 124

run debugger command, pdb module, 189

run() function

cProfile module, 190

pdb module, 186

profile module, 190

run() method

of Process objects, 416

of Thread objects, 436

runcall() function, pdb module, 186

runeval() function, pdb module, 186

running programs, 6

RuntimeError exception, 87, 214

RuntimeWarning warning, 216, 238

__rxor__() method, 61

S

!s specifier in string formatting, 74

-S command line option, 173-174

-s command line option, 173

s(tep) debugger command, pdb module, 189

safe_substitute() method, of Template objects, 289

SafeConfigParser class, configparser module, 336

same_files attribute, of dircmp objects, 315

samefile() function, os.path module, 398

sameopenfile() function, os.path module, 398

samestat() function, os.path module, 398

sample() function, random module, 255

SaveKey() function, winreg module, 410

SAX interface

XML parsing, 568

example of, 583

scaling, with concurrency, 415

sched module, 587-588

scheduler, for generators and coroutines, 447

scheme attribute

of urlparse objects, 520

of urlsplit objects, 521

scientific notation, floating point, 27

scoping rules

and module imports, 145

and self parameter in methods, 118

lexical scoping of functions, 97

of classes, 118

of function variables, 18, 96

of iteration variable in list comprehension, 109

of iteration variables, 82

script name, 157

search path, for modules, 147

search() function, re module, 284

search() method, of Regex objects, 285

searching, strings with an offset, 41

second attribute, of time objects, 338

sections() method, of ConfigParser objects, 334

secure sockets layer (SSL), 486

security

XML-RPC servers, 530

database queries, 300

marshal module, 226

pickle module, 172, 229

seed() function, random module, 254

seek() method

of IOBase objects, 350

of files, 160-161, 352

of mmap objects, 371

seekable() method, of IOBase objects, 350

select module, 415, 459

signal handling, 399

select() function

and asyncore module, 455

performance problems, 467

select module, 459

self parameter of methods, 22, 118

why required, 119

__self__ attribute

of built-in functions, 49

of methods, 49

Semaphore object

multiprocessing module, 427

threading module, 439

Semaphore objects, use for signaling, 439

Semaphore() method, of Manager objects, 429

semicolon ;, 26

send() method

of Connection objects, 422

of HTTPConnection objects, 503

of dispatcher objects, 456

of generators, 20, 53, 104

of socket objects, 484

send_bytes() method, of Connection objects, 422

send_error() method, of BaseHTTPRequestHandler objects, 509

send_header() method, of BaseHTTPRequestHandler objects, 509

send_response() method, of BaseHTTPRequestHandler objects, 509

send_signal() method, of Popen objects, 403

sendall() method, of socket objects, 484

sendcmd() method, of FTP objects, 499

sending email, example of, 514, 558

sendmail() method, of SMTP objects, 514

sendmsg() system call, lack of support, 486

sendto() method, of socket objects, 484

sentinel, use with queuing, 420, 446

sep keyword argument, to print() function, 163

sep variable, os module, 386

separator character, print() function, 163

Sequence abstract base class, 266

sequences, 39

comparison of, 70

concatenation, 67

extended slicing of, 68

in operator, 67

indexing in string formatting, 72

item assignment, 40

iteration over, 39, 69

lookup in composite string formatting, 42

negative indices, 68

operators, 67

picking random elements, 254

random sampling, 254

replication, 67

shallow copies in replication, 67

slice assignment, 40

slicing operator, 68

special methods of, 58

unpacking, 67-68

serve_forever() method

of BaseManager objects, 431

of SocketServer objects, 491

server attribute, of BaseRequestHandler objects, 490

server program, 449

TCP example, 451

UDP example, 485

example of restricting access with HTTP, 507

example with SocketServer module, 490

example with coroutines, 464

server_address attribute, of SocketServer objects, 492

server_version attribute

of BaseHTTPRequestHandler class, 508

of HTTPRequestHandler class, 507

ServerProxy() function, xmlrpc.client module, 524

Set abstract base class, 266

set comprehension, Python 3, 623

set difference operator -, 75

set intersection operator &, 75

set literals, Python 3, 622

set symmetric difference operator ^, 75

set theory, similarity to list comprehensions, 110

set type, 38, 46, 75

set union operator |, 75

set() function, 15, 77, 210

set() method

of ConfigParser objects, 334

of Element objects, 577

of Event objects, 440

of Morsel objects, 512

__set__() method, of descriptors, 58, 126

set_authorizer() method, of Connection objects, 306

set_boundary() method, of Message objects, 556

set_charset() method, of Message objects, 556

set_conversion_mode() function, ctypes module, 617

set_debug() function, gc module, 221

set_default_type() method, of Message objects, 556

set_defaults() method, of OptionParser objects, 158, 377

set_errno() function, ctypes module, 618

set_executable() function, multiprocessing module, 435

set_last_error() function, ctypes module, 618

set_param() method, of Message objects, 556

set_pasv() method, of FTP objects, 499

set_payload() method, of Message objects, 556

set_progress_handler() method, of Connection objects, 307

set_proxy() method, of Request objects, 517

set_server_documentation() method, of XMLRPCServer objects, 528

set_server_name() method, of XMLRPCServer objects, 528

set_server_title() method, of XMLRPCServer objects, 528

set_terminator() method, of asynchat objects, 453

set_threshold() function, gc module, 221

set_trace() function, pdb module, 186

set_type() method, of Message objects, 557

set_unixfrom() method, of Message objects, 557

set_usage() method, of OptionParser objects, 377

set_wakeup_fd() function, signal module, 399

setattr() function, 210

and private attributes, 128

__setattr__() method, 57-58, 131

and __slots__, 133

setblocking() method, of socket objects, 484

setcheckinterval() function, sys module, 235

setcontext() function, decimal module, 248

setDaemon() method, of Thread objects, 437

setdefault() method

of dicts, 45

of dicts and defaultdict objects, 263

setdefaultencoding() function, sys module, 235

setdefaultencoding() method, sys module, 177

setdefaulttimeout() function, socket module, 476

setdlopenflags() function, sys module, 235

setDocumentLocator() method, of ContentHandler objects, 581

setegid() function, os module, 380

seteuid() function, os module, 380

setFormatter() method, of Handler objects, 365

setgid() function, os module, 380

setgroups() function, os module, 380

setinputsize() method, of Cursor objects, 299

setitem() function, operator module, 274

__setitem__() method, 58-59

and slices, 59

setitimer() function, signal module, 399

setLevel() method

of Handler objects, 364

of Logger objects, 359

setmode() function, msvcrt module, 373

setName() method, of Thread objects, 436

setoutputsize() method, of Cursor objects, 299

setpassword() method, of ZipFile objects, 326

setpgid() function, os module, 381

setpgrp() function, os module, 381

setprofile() function

sys module, 235

threading module, 444

setrecursionlimit() function, sys module, 235

setregid() function, os module, 381

setreuid() function, os module, 381

_setroot() method, of ElementTree objects, 574

sets, 15

adding items, 15

creating from iterable objects, 46

difference operator, 15

equality of, 78

in-place modification of, 47

intersection operator, 15

length of, 75

removing items, 15

symmetric difference operator, 15

union operator, 15

updating, 15

setsid() function, os module, 381

setslice() function, operator module, 274

setsockopt() method, of socket objects, 484

setstate() function, random module, 254

__setstate__() method, 228

and copying, 220

and pickle module, 172

@setter decorator of properties, 126

settimeout() method, of socket objects, 484

setting default encoding of standard I/O, 175

settrace() function

sys module, 235

threading module, 444

setuid() function, os module, 381

setUp() method

TestCase objects, 184

of TestCase objects, 184

setup() function, distutils module, 152, 596

setup() method, of BaseRequestHandler objects, 490

setup.py file

C extensions, 596

SWIG extensions, 620

and setuptools, 154

creating, 152-153

install command, 153-154

installing in per-user site directory, 178

setuptools library, 147, 154

SetValue() function, winreg module, 411

SetValueEx() function, winreg module, 411

sha1() function, hashlib module, 559

sha224() function, hashlib module, 559

sha256() function, hashlib module, 559

sha384() function, hashlib module, 559

sha512() function, hashlib module, 559

shallow copy, 36

of dicts, 45

of lists, 40

sequence replication, 67

shared arrays, multiprocessing module, 426

shared libraries

extension modules, 148

loading with ctypes, 612

shared memory

example of passing a list, 427

multiprocessing module, 426

sharing of objects, 35

Shelf class, shelve module, 311

shell commands

collecting output from, 331

emulating in Python, 318

shell pipes, similarity to generators, 106

shelve module, 171, 311

dbhash module, 311

selecting the pickle protocol, 172

shlex module, 588

short-circuit evaluations, of boolean expressions, 78

showwarning() function, warnings module, 239

shuffle() function, random module, 255

shutdown() function, logging module, 366

shutdown() method

of BaseManager objects, 431

of SocketServer objects, 492

of socket objects, 484

shutil module, 318

side effects

in functions, 95

reasons to avoid, 96

SIG* signal names, 400

SIGHUP signal, 179

siginterrupt() function, signal module, 400

signal handling, 399

signal module, 399

signal() function, signal module, 400

signaling, with semaphores, 439

signals

close() method of generators, 104

list of, 400

mixing with threads, 402

throw() method of generators, 105

SIGTERM signal, 179

simple_producer() function, asynchat module, 453

SimpleCookie() function, http.cookies module, 512

SimpleHandler() function, wsgiref.handlers module, 543

SimpleHTTPRequestHandler class, http.server module, 507

SimpleHTTPServer module, see http.server, 506

SimpleXMLRPCServer class, xmlrpc.server module, 527

SimpleXMLRPCServer module, 527

sin() function, math module, 252

single precision floating point, 39

singleton tuple, 14

sinh() function, math module, 252

site configuration files, 177

site module, 166, 174, 177

site-packages directory, 175

sitecustomize module, 177

size attribute

of Struct objects, 291

of TarInfo objects, 322

size() method

of FTP objects, 499

of mmap objects, 371

Sized abstract base class, 265

sizeof() function, ctypes module, 618

skippedEntity() method, of ContentHandler objects, 581

sleep() function, time module, 406

sleeping, 406

until signal received, 399

slice assignment, lists, 12

slice objects, 51, 53

and indexing methods, 59

attributes of, 54

slice type, 51

slice() function, 53, 210

slices, 39

and special methods, 59

and xrange objects, 44

assignment to, 40, 69

deletion of, 40, 69

multidimensional, 59

slicing operator [:], 67-68

on lists, 12

on strings, 11

__slots__ attribute

and __dict__ attribute of instances, 50

compatibility with other code, 133

inheritance, 133

of class definitions, 132

optimization, 196

Smalltalk, differences in object system, 124

SMTP protocol, example of sending a message, 514

SMTP() function, smtplib module, 514

smtpd module, 587

SMTPHandler class, logging module, 363

smtplib module, 513

sndhdr module, 588

sniff() method, of Sniffer objects, 550

Sniffer() function, csv module, 550

SO_* socket options, socket module, 479

SOCK_* constants, socket module, 470

socket attribute, of SocketServer objects, 492

socket module, 469

socket() function, socket module, 476

socket, definition of, 449

socket_type attribute, of SocketServer class, 493

SocketHandler class, logging module, 363

socketpair() function, socket module, 477

sockets

address families, 470

methods on, 478

polling with select(), 459

specifying network addresses, 471

types of, 470

SocketServer module, 489

and Python 3, 489

changing server parameters, 492

softspace attribute, of files, 161

sort() method, of lists, 40-41

sorted() function, 210

sorting

changing behavior of, 40

in-place on lists, 40

requirements for objects, 57

reverse order, 40

use of operator module, 275

source code encoding, 31

Python 3, 622

span() method, of MatchObject objects, 286

spawnl() function, os module, 393

spawnle() function, os module, 393

spawnlp() function, os module, 393

spawnlpe() function, os module, 393

spawnv() function, os module, 392

spawnve() function, os module, 393

spawnvp() function, os module, 393

spawnvpe() function, os module, 393

special methods, 21, 54

special symbols, 30

speedup, definition of, 192

split() function

os.path module, 398

re module, 284

split() method

of Regex objects, 285

of strings, 14, 41, 43

splitdrive() function, os.path module, 398

splitext() function, os.path module, 398

splitlines() method, of strings, 44

splitting, strings, 14, 43

splitunc() function, os.path module, 398

SpooledTemporaryFile() function, tempfile module, 324

sprintf() function equivalent, 70

spwd module, 587

SQL queries

SQL injection attack, 300

examples of, 309

executing on database, 297

how to form, 300

similarity to list comprehensions, 111

SQLite database, 303

sqlite3 module, 303

sqrt() function, math module, 252

sqrt() method, of Decimal objects, 243

ssl module, 486

SSL, example of creating certificates, 489

st_* attributes, of stat objects, 389

stack frames, 52

in tracebacks, 53

stack size, for threads, 444

stack() function, inspect module, 225

stack_size() function, threading module, 444

Stackless Python, 467

standard I/O streams, 161

and integrated development environments, 162

setting the default encoding, 175

standard error, 157

standard input and output, 10

standard library reorganization, Python 3, 634

standard_b64decode() function, base64 module, 546

standard_b64encode() function, base64 module, 546

StandardError exception, 87

starmap() function, itertools module, 272

start attribute, of slices, 54

start() method

of BaseManager objects, 431

of MatchObject objects, 286

of Process objects, 416

of Thread objects, 436

of Timer objects, 438

of TreeBuilder objects, 577

startDocument() method, of ContentHandler objects, 582

startElement() method, of ContentHandler objects, 582

startElementNS() method, of ContentHandler objects, 582

startfile() function, os module, 393

startPrefixMapping() method, of ContentHandler objects, 582

startswith() method, of strings, 44

startup script, in interactive mode, 174

stat module, 387, 587

stat() function

os module, 388

os.path module, 398

stat_float_times() function, os module, 389

statement termination, 7

and semicolons, 7

statements

breaking across multiple lines, 9

putting on the same line, 25-26

running in the debugger, 186

static method, 22, 48, 123, 125

practical use of, 123

@staticmethod decorator, 22, 48, 123, 125, 210

statistics, random number distributions, 255

status attribute, of HTTPResponse objects, 504

statvfs() function, os module, 389

stderr attribute, of Popen objects, 404

stderr variable, sys module, 161, 232

__stderr__ variable, sys module, 162, 232

stdin attribute, of Popen objects, 404

stdin variable, sys module, 10, 161, 232

__stdin__ variable, sys module, 162, 232

stdout attribute, of Popen objects, 404

stdout variable, sys module, 10, 161, 232

__stdout__ variable, sys module, 162, 232

step attribute, of slices, 54

StopIteration exception, 59, 87, 215

and generators, 103

storbinary() method, of FTP objects, 499

storlines() method, of FTP objects, 499

str type, 38

str() function, 11, 56, 76, 210

and print, 162

difference from repr(), 12

__str__() method, 55-56

StreamError exception, tarfile module, 322

StreamHandler class, logging module, 363

StreamReader class, codecs module, 278

streamreader() method, of CodecInfo objects, 278

StreamRequestHandler class, SocketServer module, 491

streams, 470

StreamWriter class, codecs module, 278

streamwriter() method, of CodecInfo objects, 278

strerror() function, os module, 381

strftime() function, time module, 406

strftime() method

of date objects, 337

of time objects, 338

‘strict’ error handling, Unicode encoding, 166

string attribute, of MatchObject objects, 286

string formatting, 70

!r specifier, 74

!s specifier, 74

alignment, 73

attribute lookup, 72

codes for % operator, 70-71

customizing format() method, 74

dictionaries, 72

dictionary lookup, 72

fill characters, 73

format specifiers, 72

formatting operator %, 70

string interpolation, 72, 163

string literals, 27

Unicode characters, 28

and Unicode encodings, 29

and documentation strings, 30

byte strings, 29

unicode characters in source code, 31

string module, 287

Template strings, 164

string_at() function, ctypes module, 618

StringIO class, io module, 353

stringprep module, 586

strings, 11

Unicode, 41, 165

and numeric calculations, 11

as a dictionary key, 16

as in-memory text files, 353

as sequences, 39

basestring object for type checking, 202

byte literals, 29

byte strings, 41, 202

case conversion, 43-44

character substitution, 42

comparison of, 70

concatenation, 11

concatenation of adjacent literals, 27

creating custom formatters, 288

disabling escape codes in literals, 29

encoding for URLs, 522

escape codes in literals, 27

escaping characters for use in HTML, 536

escaping characters for use in XML, 583

executing Python code contained within, 115

format() method, 8, 72

formatting, 8, 42

formatting in log messages, 358

immutability of, 41, 69

indexing, 11

internal representation, 28

iterating over characters, 17

joining, 43

line structure, 11

mixing byte strings and Unicode, 70

mutable byte arrays, 202

partitioning, 41

regular expressions, 281

replacing substrings, 41

searching for substrings, 41

slices, 11

sorting and internationalization, 70

specifiers for format() method, 72-73

splitting, 43

splitting into fields, 14, 41

stripping, 43

unescaping XML character references, 583

strip() method, of strings, 44

stripping

control characters from a string, 42

strings, 44

strptime() function, time module, 343, 407

strptime() method, of datetime class, 339

Struct class, struct module, 291

struct module, 290

Structure class, ctypes module, 614

structures, and tuples, 14

sub() function

operator module, 273

re module, 284

sub() method, of Regex objects, 285

__sub__() method, 60

subclass, 119

__subclasscheck__() method, 57, 136

subdirs attribute, of dircmp objects, 315

SubElement() function, xml.etree.ElementTree module, 575

subn() function, re module, 284

subn() method, of Regex objects, 285

subprocess module, 402

subprocess, definition of, 413

substitute() method

of Template objects, 289

of Template strings, 164

substrings

checking for existence using in, 69

searching for, 41

subtraction operator -, 65

sucessful() method, of AsyncResult objects, 425

sum() function, 39-40, 67, 210

accuracy of, 252

and decimal module, 69

restriction to numeric data, 39

versus math.fsum() function, 252

sunau module, 588

super() function, 120, 210

Python 3, 210, 627

superclass, 119

calling methods in, 120

super() function, 120

supporting both Python 2 and 3, 638

supports_unicode_filenames variable, os.path module, 398

surrogate pair, 28, 41

suspension, of threads, 443

swapcase() method, of strings, 44

SWIG, 591

example of, 619

interface file, 619

switch statement, lack of, 9

symbol module, 586

symbolic links, testing a filename for, 397

symlink() function, os module, 389

symmetric difference operator ^, of sets, 15

symmetric_difference() method, of sets, 46

symmetric_difference_update() method, of sets, 47

sync() method

of dbm-style database objects, 310

of shelve objects, 311

synchronization primitives

multiprocessing module, 427

threading module, 438

synchronization

of close() method of generators, 104

of concurrent programs, 414

of throw() method of generators, 105

SyntaxError exception, 87, 215

Python 3 print statement, 6

and default arguments, 93

and except statements, 85

SyntaxWarning warning, 216, 238

sys module, 13, 229

sys.argv variable, 13, 157, 174

sys.displayhook variable, 176

sys.exec_prefix variable, 177

sys.exit() function, 179

sys.modules variable, 144, 149

sys.path variable, 147

and site module, 177

third-party modules, 154

sys.prefix variable, 177

sys.ps1 variable, 176

sys.ps2 variable, 176

sys.stderr variable, 157, 161

sys.stdin variable, 161

sys.stdout variable, 161

sys_version attribute, of BaseHTTPRequestHandler class, 508

sysconf() function, os module, 395

syslog module, 587

SysLogHandler class, logging module, 363

system calls, os module, 378

system error codes, 344

system() function, os module, 393

system.listMethods() method, of ServerProxy objects, 525

SystemError exception, 87, 215

SystemExit exception, 7, 87-88, 157, 179, 215

T

-t command line option, 26, 173-174

tab escape code in strings, 28

tabcheck attribute, of sys.flags, 230

TabError exception, 26, 87, 215

tabnanny module, 586

tabs, and indentation, 26

tag attribute, of Element objects, 576

tagName attribute, of DOM Element objects, 572

tail attribute, of Element objects, 576

tail command, example with generators, 19

tail-recursion optimization, lack of, 112

takewhile() function, itertools module, 272

tan() function, math module, 252

tanh() function, math module, 252

TarError exception, tarfile module, 322

TarFile objects, tarfile module, 320

tarfile module, 319

TarInfo objects, tarfile module, 321

task scheduler, example with coroutines and select(), 460

task_done() method

of JoinableQueue objects, 419

of Queue objects, 445

tasklets, 446

asynchronous I/O, 460

tasks, and coroutines, 20

tb_* attributes, of traceback objects, 53

tb_lineno() function, traceback module, 236

tbreak debugger command, pdb module, 189

tcgetpgrp() function, os module, 385

TCP connection, diagram of, 450

TCP protocol, 449

example code, 451

TCP_* socket options, socket module, 482

TCPServer class, SocketServer module, 491

tcsetpgrp() function, os module, 385

tearDown() method

TestCase objects, 184

of TestCase objects, 184

tee() function, itertools module, 273

tell() method

of IOBase objects, 350

of files, 160-161

of mmap objects, 371

telnetlib module, 587

tempdir variable, tempfile module, 324

tempfile module, 323

Template class, string module, 289

Template strings

string module, 164

use in CGI script, 537

template attribute, of Template objects, 290

template variable, tempfile module, 324

temporary files, 323

TemporaryFile() function, tempfile module, 323

terminate() method

of Pool objects, 425

of Popen objects, 403-404

of Process objects, 416

terminating statements with semicolons, 7

termination

immediate without garbage collection, 391

of programs, 179

of threads, 443

registering cleanup functions, 219

sys.exit() function, 233

without garbage collection, 179

termios module, 587

test module, 586

test() function, cgi module, 537

TestCase class, unittest module, 184

testing

doctest module, 181

documentation strings, 181

limitations of doctest, 183

unit testing, 183

testmod() function

doctest() module, 182

doctest module, 182

testzip() method, of ZipFile objects, 326

Text class, xml.dom.minidom module, 572

text I/O, 353

text attribute, of Element objects, 576

text file mode, 159

text replacement, replace() method of strings, 41

text versus bytes in Python 3, 629

text_factory attribute, of Connection objects, 308

TextIOBase abstract base class, 354

TextIOWrapper class, io module, 353

textwrap module, 586

third-party libraries, and Python 3, 621

third-party packages

and C/C++ code, 154

and sys.path variable, 154

installation of, 154

installing in per-user site directory, 154, 178

this pointer, self parameter of methods, 119

Thread class, threading module, 436

thread attribute, of Record objects, 359

threading module, 436

synchronization primitives, 438

ThreadingMixIn class, SocketServer module, 494

ThreadingTCPServer class, SocketServer module, 494

ThreadingUDPServer class, SocketServer module, 494

threadName attribute, of Record objects, 359

threads

CPU-bound tasks, 444

adding to network servers, 494

atomic operations and disassembly, 193

check interval, 234

close() method of generators, 104

compared to coroutines, 467

condition variables, 441

daemonic, 436

database modules, 302

decimal module, 249

definition of, 413

events, 440

extension modules, 607

global interpreter lock, 414, 444

local storage, 443

main thread, 413

mutex lock, 438

obtaining number of active, 443

random number generation, 256

reentrant mutex lock, 438

scaling properties, 415

scheduling of, 414

semaphores, 439

setting stack size, 444

setting the name, 436

signal handling, 402

signaling with semaphores, 439

suspending, 443

synchronization of, 414

termination of, 443

throw() method of generators, 105

use of queues, 444

worker thread example, 446

threadsafety variable, database API, 302

throw() method, of generators, 53, 105-106

time and date parsing, 407

time class, datetime module, 338

time manipulation, 336

time module, 191, 405

accuracy of time functions, 408

current time, 405

time parsing, 343

Time() function, database API, 301

time() function, time module, 191, 407

time() method, of datetime objects, 340

timedelta class, datetime module, 340

TimedRotatingFileHandler class, logging module, 363

TimeFromTicks() function, database API, 301

timeit module, 191

timeit() function

cProfile module, 190

timeit module, 191

timeout attribute, of SocketServer class, 493

timeout exception, socket module, 485

timeout, example with alarm signals, 401

Timer() function, threading module, 437

times() function, os module, 394

Timestamp() function, database API, 301

TimestampFromTicks() function, database API, 301

timetuple() method, of date objects, 337

timetz() method, of datetime objects, 340

timezone variable, time module, 405

timing measurements, 191

TIPC protocol, 470

address format, 472

TIPC_* constants, socket module, 473

title() method, of strings, 44

Tkinter module, 588

today() method, of date class, 336

tofile() method, of array objects, 260

token module, 586

tokenize module, 586

tolist() method, of array objects, 260

toordinal() method, of date objects, 337

toprettyxml() method, of DOM Node objects, 572

tostring() function, xml.etree.ElementTree module, 578

tostring() method, of array objects, 260

total_changes attribute, of Connection objects, 308

tounicode() method, of array objects, 260

toxml() method, of DOM Node objects, 573

trace() function, inspect module, 225

traceback messages, 22

traceback module, 235

traceback objects, 51-52

attributes of, 53

stack frames, 53

__traceback__ attribute, of Exception objects, 213

tracebacklimit variable, sys module, 232

tracebacks

creating with traceback module, 236

limiting the amount of output, 232

TracebackType type, 51, 237

trailing J on complex number literals, 27

trailing L on long integers, 27

trailing comma

and tuples, 14

print statement, 162

transfercmd() method, of FTP objects, 500

translate() method, of strings, 42, 44

traps attribute, of Context objects, 247

TreeBuilder() function, xml.etree.ElementTree module, 577

triangular() function, random module, 256

triple-quoted strings, 11

and variable interpolation, 163

True value, 9, 27, 38

truediv() function, operator module, 273

__truediv__() method, 60

trunc() function, math module, 252

truncate() method

of IOBase objects, 350

of files, 160

truncating division operator //, 65

truncation, of integer division, 61, 65

truth value testing, 78

truth values, 9

truth() function, operator module, 274

try statement, 22, 84-85

-tt command line option, 26, 173-174

tty module, 587

ttyname() function, os module, 385

tuning strategies, 194

tuple type, 38

tuple unpacking, and for-loops, 15

tuple() function, 77, 211

tuples, 14

and string formatting, 70

as dictionary key, 16

as dictionary keys, 74

as sequence, 39

comparison on, 70

concatenation, 14

creating a list of from dictionary, 45

creating with named attributes, 264

immutability, 14

immutability of, 69

indexing, 14

memory savings of, 14

omission of parantheses, 14

problems with using as data structure, 264

representing records, 14

singleton, 14

slicing, 14

unpacking in Python 3, 623

unpacking in iteration, 82

use by standard library, 265

use in list comprehensions, 109

versus lists, 14

Twisted library, 415, 467

two-dimensional lists, 13, 15

type, 47

type attribute

of FieldStorage objects, 535

of TarInfo objects, 322

of socket objects, 484

type checking

example with metaclass, 140

of objects, 34

performance impact of, 34

problem with proxy objects, 135

type coercion, and operator overloading, 134

type comparison of objects, 34

type conversion, 76

lack of implicit conversion, 62

of columns in a datafile, 37

special methods for, 62

type hierarchies, 138

type objects, 50

type of objects, 33

type() function, 34, 211

and exceptions, 89

type() metaclass, 138

type_options attribute, of FieldStorage objects, 535

typecode attribute, of array objects, 259

TypeError exception, 87, 215

and function calls, 94

and type coercion, 62

method resolution order, 122

types module, 47, 237

and Python 3, 237

types

boolean, 38

built-in, 37, 201

callable, 47

dictionary, 44

floating point, 38

frozenset, 46

integers, 38

of sockets, 470

set, 46

type of, 47

tzinfo attribute, of time objects, 338

tzname variable, time module, 405

tzname() method

of time objects, 339

of tzinfo objects, 342

tzset() function, time module, 407

U

U escape code, in strings, 28

u escape code, in strings, 28

-U command line option, 28, 173

‘U’ mode, to open() function, 159

u character, before a string literal, 28

-u command line option, 173

u(p) debugger command, pdb module, 189

UDP client example, 486

UDP communication, diagram of, 451

UDP protocol, 449

UDP server example, 485

UDPServer class, SocketServer module, 491

uid attribute, of TarInfo objects, 322

umask() function, os module, 381

unalias debugger command, pdb module, 189

uname attribute, of TarInfo objects, 322

uname() function, os module, 381

unary minus operator -, 65

unary plus operator +, 65

unbound method, 49

and Python 3, 49

UnboundLocalError exception, 87, 98, 215

unbuffered file I/O, 159

unconsumed_tail attribute, of decompressobj objects, 329

underscores, usage in identifiers, 26

unescape() function, xml.sax.saxutils module, 583

ungetch() function, msvcrt module, 373

ungetwch() function, msvcrt module, 373

unhexlify() function, binascii module, 548

unichr() function, 77, 211

Unicode character database, 293

Unicode characters, representation of, 41

Unicode string literals, 28

Unicode strings, 41

and WSGI, 541

common encodings, 166

decomposing, 295

encoding and decoing, 165

encoding in network programs, 452

error handling options, 166

handling of, 165

mixing with byte strings, 167

normalizing, 296

regular expressions, 281

unicode attribute, of sys.flags, 230

unicode type, 38

unicode() function, 211

and Python 3, 211

Unicode

Python 2 vs. Python 3, 28

and BOM characters, 168

and XML, 168

byte order marker, 280

character encoding and decoding, 42

character properties database, 170

code points, 28

common encodings, 168-169

encoding in string literals, 29

encoding of source code, 31

file I/O, 167

mixing with byte strings, 70

normalization of strings, 171

specifying characters in string literals, 28

surrogate pairs, 28, 41

using 32-bit character code points, 41

unicode-escape encoding, description of, 170

unicodedata module, 170, 293

UnicodeDecodeError exception, 87, 215

UnicodeEncodeError exception, 87, 215

Python 3 interactive mode, 175

UnicodeError exception, 87, 166, 215

UnicodeTranslateError exception, 87, 215

unidata_version variable, unicodedata module, 296

unification of integer and long types, 38

uniform access principle, 125

uniform type arrays, 259

uniform() function, random module, 255

UnimplementedFileMode exception, http.client module, 504

Union class, ctypes module, 614

union operator |, of sets, 15

union() method, of sets, 46

unit testing

Python 3 migration, 635

example, 184

unittest module, 183

unittest module, 183

example, 184

universal newline mode, 159

UNIX domain protocol, 470

address format, 472

Unix systems log, issuing message to, 363

Unix

#! execution of programs, 6

per-user site directory, 177

time epoch definition, 405

UnixDatagramServer class, SocketServer module, 491

UnixStreamServer class, SocketServer module, 491

UnknownHandler class, urllib.request module, 518

UnknownProtocol exception, http.client module, 504

UnknownTransferEncoding exception, http.client module, 504

unlink() function, os module, 390

unloading modules, 149

unpack() function, struct module, 290

unpack() method, of Struct objects, 291

unpack_from() function, struct module, 291

unpack_from() method, of Struct objects, 291

unpacking

binary data structures, 290

of sequences, 67-68

of tuples, 14

Unpickler class, pickle module, 228

unquote() function, urllib.parse module, 522

unquote_plus() function, urllib.parse module, 522

unquote_to_bytes() function, urllib.parse module, 522

unregister() method, of Poll objects, 460

unregister_dislect() function, csv module, 551

unsetenv() function, os module, 381

until debugger command, pdb module, 189

unused_data attribute, of decompressobj objects, 329

unwrap() method, of ssl objects, 488

update() method

of dicts, 45

of digest objects, 559

of hmac objects, 560

of sets, 15, 47

update_wrapper() function, functools module, 269

updating a dictionary, 45

uploading

files in CGI scripts, 536

files to a HTTP server with POST, 505

files to an FTP server, 500

packages to pypi, 155

upper() method, of strings, 44

uppercase variable, string module, 287

urandom() function, os module, 396

urldefrag() function, urllib.parse module, 521

urlencode() function, urllib.parse module, 522

URLError exception, 516

urllib.error module, 523

urljoin() function, urllib.parse module, 521

urllib module, 522

see urllib.request, 515

urllib package, 514

urllib.error module, 523

urllib.parse module, 520

urllib.request module, 515

urllib.response module, 520

urllib.robotparser module, 523

urllib2 module, see urllib.request, 515

urlopen() function, urllib.request module, 515

urlparse module, 520

urlparse() function, urllib.parse module, 520

urlsafe_b64decode() function, base64 module, 546

urlsafe_b64encode() function, base64 module, 546

urlsplit() function, urllib.parse module, 521

urlunparse() function, urllib.parse module, 521

urlunsplit() function, urllib.parse module, 521

user directory, installation of packages, 154

user module, 586

—user option to setup.py, 154

user-agent header in HTTP requests, changing, 517

username attribute

of urlparse objects, 520

of urlsplit objects, 521

UserWarning warning, 216, 238

using Python as a calculator, 6

utcfromtimestamp() method, of datetime class, 339

utcnow() method, of datetime class, 339

utcoffset() method

of time objects, 339

of tzinfo objects, 342

utctimetuple() method, of datetime objects, 340

UTF-16 encoding, description of, 170

UTF-8

compatibility with ASCII, 170

description of, 169-170

encoding and decoding, 42

including in string literals, 29

lexicographic ordering, 170

utime() function, os module, 390

uu module, 587

V

-V command line option, 173

-v command line option, 173-174

validator() function, wsgiref.handlers module, 543

value attribute

of FieldStorage objects, 535

of Morsel objects, 512

Value() function, multiprocessing module, 426

Value() method, of Manager objects, 429

ValueError exception, 87, 215

and lists, 40

and strings, 41

valuerefs() method, of WeakValueDictionary objects, 241

values() method

of Message objects, 552

of dicts, 45

of dicts in Python 3, 632

ValuesView abstract base class, 266

variable interpolation in strings, 163

variable keyword arguments in function definition, 95

variable number of arguments in function definition, 94

variables, 7

as names of objects, 35

binding and module imports, 145

binding of globals in functions, 98

class, 117-118

in nested functions, 97

iteration, 82

naming rules, 26

scope of, 96, 98

vars() function, 72, 211

verbose attribute, of sys.flags, 230

verify_request() method, of SocketServer class, 493

version attribute, of HTTPResponse objects, 504

version information, of interpreter, 231

version variable, sys module, 232

version_info variable, sys module, 232

vformat() method, of Formatter objects, 288

view objects, Python 3, 632

volume attribute, of ZipInfo objects, 327

vonmisesvariate() function, random module, 256

W

-W command line option, 216, 239-240

‘w’ mode, to open() function, 159

w(here) debugger command, pdb module, 189

wait() function, os module, 394

wait() method

of AsyncResult objects, 425

of Condition objects, 441

of Event objects, 440

of Popen objects, 404

wait3() function, os module, 394

wait4() function, os module, 394

waitpid() function, os module, 394

walk() function, os module, 390

walk() method, of Message objects, 554

wall-clock time, obtaining, 191

warn() function, warnings module, 216, 239

warn_explicit() function, warnings module, 239

Warning warning, 216, 238

warning() method, of Logger objects, 357

warnings module, 238

warnings

converting into exceptions, 239

difference from exceptions, 216

suppression of, 238

warnoptions variable, sys module, 232

WatchedFileHandler class, logging module, 363

wave module, 588

WCOREDUMP() function, os module, 394

weak reference, 130

weak references, 240

WeakKeyDictionary class, weakref module, 241

weakref module, 130, 240

WeakValueDictionary class, weakref module, 241

web frameworks, 538

and template strings, 164

web programming, 531

web server

custom handling of requests, 510

running standalone in Python, 508

webbrowser module, 544

weekday() method, of date objects, 338

weibullvariate() function, random module, 256

well known port numbers, 450

WEXITSTATUS() function, os module, 394

wfile attribute

of BaseHTTPRequestHandler objects, 509

of StreamRequestHandler objects, 491

whichdb module, 310

whichdb() function, dbm module, 310

while statement, 8, 82

whitespace variable, string module, 287

WIFCONTINUED() function, os module, 395

WIFEXITED() function, os module, 394

WIFSIGNALED() function, os module, 395

WIFSTOPPED() function, os module, 395

WinDLL() function, ctypes module, 612

Windows, 331

accesing registry, 408

accessing registry, 175

creating a binary distribution with distutils, 153

double-clicking on Python programs, 176

drive letters in filenames, 399

file locking, 373

issuing message to event log, 362

list of error codes, 346

main program with multiprocessing module, 417

per-user site directory, 177

process fork with multiprocessing, 435

running programs, 6

WindowsError exception, 215

Wing IDE, 5

winreg module, 408

winsound module, 588

winver variable, sys module, 232

with statement, 62, 89

and exceptions, 23

and locking, 89

decimal module, 248

locking primitives, 442

work pools, of processes, 424

wrap_socket() function, ssl module, 486

wrapper functions, 95

and closures, 100

example of, 101

in extension modules, 594

wrappers, and attribute binding methods, 132

@wraps decorator, functools module, 114, 269

writable() method

of IOBase objects, 350

of dispatcher objects, 456

write() function, os module, 385

write() method

of BufferWriter objects, 352

of ConfigParser objects, 334

of ElementTree objects, 575

of FileIO objects, 350

of StreamWriter objects, 278

of TextIOWrapper objects, 353

of ZipFile objects, 326

of files, 10, 159-160

of mmap objects, 372

of ssl objects, 488

write_byte() method, of mmap objects, 372

writelines() method

of IOBase objects, 350

of StreamWriter objects, 278

of files, 159-160

writepy() method, of ZipFile objects, 326

writer() function, csv module, 549

writerow() method

of csv DictWriter objects, 550

of csv writer objects, 549

writerows() method

of csv DictWriter objects, 550

of csv writer objects, 550

writestr() method, of ZipFile objects, 327

writexml() method, of DOM Node objects, 573

writing to a file, 159

WSGI (Web Server Gateway Interface), 540

WSGI

application specification, 540

example of, 541

integration with web frameworks, 543

processing form fields, 541

running a stand-alone server, 542

running in CGI scripts, 542

use of generators for I/O, 165

validation of applications, 543

wsgi.* environment variables, 540

wsgiref package, 542

wsgiref.handlers module, 542

wsgiref.simple_server module, 542

WSTOPSIG() function, os module, 395

wstring_at() function, ctypes module, 618

WTERMSIG() function, os module, 395

X

x escape code, in strings, 28

-x command line option, 173-174

xdrlib module, 587

xml package, 568

XML() function, xml.etree.ElementTree module, 575

XML

escaping and unescaping characters, 583

example document, 569

incremental parsing of large files, 579

namespaces in ElementTree module, 578

parsing, 568

XML-RPC, 524

XML-RPC server, multithreaded example, 494

XML-RPC

example of, 529

server customization, 530

xml.dom.minidom module, 570

xml.etree.ElementTree module, 573

xml.sax module, 580

xml.sax.saxutils module, 583

‘xmlcharrefreplace’ error handling, 166-167

XMLGenerator() function, xml.sax.saxutils module, 584

XMLID() function, xml.etree.ElementTree module, 575

xmlrpc package, 524

xmlrpc.client module, 524

xmlrpc.server module, 527

xmlrpclib module, 524

XMLRPCServer class, xmlrpc.server module, 527

xor() function, operator module, 274

__xor__() method, 60

XPATH, 569

xrange type, 38

xrange() compared to a list, 44

xrange() function, 17, 44, 211

and Python 3, 17, 44, 211

XSLT, 569

Y

Y2K handling, 407

year attribute, of date objects, 337

yield expressions, 20, 104

yield statement, 19, 53, 102

and context managers, 90

use with I/O, 164-165

Z

ZeroDivisionError exception, 87, 215

zfill() method, of strings, 44

.zip files

and modules, 147

decoding and encoding, 324

use as a code archive, 147

zip() function, 83, 211

and Python 3, 211

future_builtins module, 217

type-conversion example, 37

zipfile module, 324

ZipFile() function, zipfile module, 325

zipimport module, 586

ZipInfo() function, zipfile module, 325

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.239.44