Dive Into Python 3
Book information
Description
Title page ......Page 2 Copyright Page ......Page 3 Contents at a Glance......Page 5 Table of Contents ......Page 6 Foreword......Page 14 About the Author......Page 16 About the Technical Reviewer......Page 17 Acknowledgments......Page 18 Which Python Is Right for You?......Page 19 Installing on Microsoft Windows......Page 20 Installing on Mac OS X......Page 29 Installing on Ubuntu Linux......Page 41 Using the Python Shell......Page 48 Python Editors and IDEs......Page 50 CHAPTER 1 Your First Python Program......Page 52 Declaring Functions......Page 53 Optional and Named Arguments......Page 54 Documentation Strings......Page 56 The import Search Path......Page 57 Everything Is an Object......Page 58 Indenting Code......Page 59 Exceptions......Page 60 Catching Import Errors......Page 62 Running Scripts......Page 63 Further Reading Online......Page 64 Booleans......Page 65 Numbers......Page 66 Coercing Integers to Floats and Vice Versa......Page 67 Common Numerical Operations......Page 68 Fractions......Page 69 Numbers in a Boolean Context......Page 70 Creating a List......Page 71 Slicing a List......Page 72 Adding Items to a List......Page 73 Searching For Values in a List......Page 75 Removing Items from a List: Bonus Round......Page 76 Lists in a Boolean Context......Page 77 Tuples......Page 78 Assigning Multiple Values at Once......Page 80 Sets......Page 81 Modifying a Set......Page 83 Removing Items from a Set......Page 84 Common Set Operations......Page 85 Sets in a Boolean Context......Page 87 Modifying a Dictionary......Page 88 Mixed-Value Dictionaries......Page 89 Dictionaries in a Boolean Context......Page 90 None in a Boolean Context......Page 91 Further Reading Online......Page 92 The Current Working Directory......Page 93 Working with Filenames and Directory Names......Page 94 Listing Directories......Page 96 Constructing Absolute Pathnames......Page 97 List Comprehensions......Page 98 Dictionary Comprehensions......Page 100 Set Comprehensions......Page 101 Further Reading Online......Page 102 CHAPTER 4 Strings ......Page 103 Unicode......Page 104 Formatting Strings......Page 106 Compound Field Names......Page 107 Format Specifiers......Page 109 Other Common String Methods......Page 110 Slicing a String......Page 111 Strings versus Bytes......Page 112 Character Encoding of Python Source Code......Page 115 Further Reading Online......Page 116 Case Study: Street Addresses......Page 118 Case Study: Roman Numerals......Page 120 Checking for Thousands......Page 121 Checking for Hundreds......Page 122 Using the {n,m} Syntax......Page 124 Checking for Tens and Ones......Page 125 Verbose Regular Expressions......Page 127 Case Study: Parsing Phone Numbers......Page 129 Further Reading Online......Page 134 CHAPTER 6 Closures and Generators ......Page 135 I Know, Let’s Use Regular Expressions!......Page 136 A List of Functions......Page 138 A List of Patterns......Page 140 A File of Patterns......Page 143 Generators......Page 144 A Fibonacci Generator......Page 146 A Plural Rule Generator......Page 147 Further Reading Online......Page 148 CHAPTER 7 Classes and Iterators ......Page 149 The __init__() Method......Page 150 Instantiating Classes......Page 151 Instance Variables......Page 152 A Fibonacci Iterator......Page 153 A Plural Rule Iterator......Page 155 Further Reading Online......Page 160 CHAPTER 8 Advanced Iterators ......Page 161 Finding the Unique Items in a Sequence......Page 163 Generator Expressions......Page 165 Calculating Permutations … the Lazy Way......Page 167 Other Fun Stuff in the itertools Module......Page 168 A New Kind of String Manipulation......Page 172 Evaluating Arbitrary Strings as Python Expressions......Page 174 Further Reading Online......Page 178 CHAPTER 9 Unit Testing ......Page 179 A Single Question......Page 180 Halt and Catch Fire......Page 186 More Halting, More Fire......Page 189 And One More Thing …......Page 192 A Pleasing Symmetry......Page 194 More Bad Input......Page 198 CHAPTER 10 Refactoring ......Page 202 Handling Changing Requirements......Page 205 Refactoring......Page 209 Further Reading Online......Page 213 Reading from Text Files......Page 214 Character Encoding Rears Its Ugly Head......Page 215 Stream Objects......Page 216 Reading Data from a Text File......Page 217 Closing Files......Page 219 Reading Data One Line at a Time......Page 220 Writing to Text Files......Page 222 Character Encoding Again......Page 223 Binary Files......Page 224 Streams Objects from Nonfile Sources......Page 225 Handling Compressed Files......Page 226 Standard Input, Output, and Error......Page 227 Redirecting Standard Output......Page 228 Further Reading Online......Page 231 CHAPTER 12 XML......Page 232 A 5-Minute Crash Course in XML......Page 233 The Structure of an Atom Feed......Page 236 Parsing XML......Page 238 Elements Are Lists......Page 239 Attributes Are Dictionaries......Page 240 Searching for Nodes Within an XML Document......Page 241 Going Further with lxml......Page 244 Generating XML......Page 246 Parsing Broken XML......Page 249 Further Reading Online......Page 251 A Quick Note About the Examples in this Chapter......Page 252 Saving Data to a Pickle File......Page 253 Loading Data from a Pickle File......Page 255 Pickling Without a File......Page 256 Debugging Pickle Files......Page 257 Saving Data to a JSON File......Page 260 Serializing Datatypes Unsupported by JSON......Page 262 Loading Data from a JSON File......Page 267 Further Reading Online......Page 269 CHAPTER 14 HTTP Web Services ......Page 271 Caching......Page 272 Last-Modified Checking......Page 273 ETags......Page 274 Redirects......Page 275 How Not to Fetch Data Over HTTP......Page 276 What’s On the Wire?......Page 277 Introducing httplib2......Page 280 Caching with httplib2......Page 283 Handling Last-Modified and ETag Headers with httplib2......Page 286 Handling Compression with httplib2......Page 288 Handling Redirects with httplib2......Page 289 Beyond HTTP GET......Page 292 Beyond HTTP POST......Page 296 Further Reading Online......Page 298 Why Auto-Detection Is Difficult......Page 299 Escaped Encodings......Page 300 Single-Byte Encodings......Page 301 Running 2to3......Page 302 A Short Digression Into Multi-File Modules......Page 305 False Is Invalid Syntax......Page 307 No Module Named Constants......Page 308 Name 'file' Is Not Defined......Page 309 Can’t Use a String Pattern on a Bytes-Like Object......Page 310 Can’t Convert 'bytes' Object to str Implicitly......Page 312 Unsupported Operand type(s) for +: 'int' and 'bytes'......Page 315 ord() Expected String of Length 1, but int Found......Page 316 Unorderable Types: int() >= str()......Page 319 Global Name 'reduce' Is not Defined......Page 321 Lessons Learned......Page 323 CHAPTER 16 Packaging Python Libraries......Page 324 Things Distutils Can’t Do for You......Page 325 Directory Structure......Page 326 Writing Your Setup Script......Page 327 Examples of Good Package Classifiers......Page 329 Creating a Source Distribution......Page 332 Creating a Graphical Installer......Page 334 Building Installable Packages for Other Operating Systems......Page 335 Adding Your Software to the Python Package Index......Page 336 The Many Possible Futures of Python Packaging......Page 337 Further Reading Online......Page 338 print Statement......Page 339 unicode() Global Function......Page 340 Comparison......Page 341 has_key() Dictionary Method......Page 342 Renamed or Reorganized Modules......Page 343 urllib......Page 344 dbm......Page 345 Other Modules......Page 346 Relative Imports Within a Package......Page 348 next() Iterator Method......Page 349 map() Global Function......Page 350 reduce() Global Function......Page 351 intern() Global Function......Page 352 execfile Statement......Page 353 try...except Statement......Page 354 throw Method on Generators......Page 356 xrange() Global Function......Page 357 func_* Function Attributes......Page 358 xreadlines() I/O Method......Page 359 lambda Functions that Take a Tuple Instead of Multiple Parameters ......Page 360 __nonzero__ Special Method......Page 361 sys.maxint......Page 362 StandardError Exception......Page 363 types Module Constants......Page 364 basestring Datatype......Page 365 sys.exc_type, sys.exc_value, sys.exc_traceback......Page 366 Metaclasses......Page 367 buffer() Global Function (Explicit)......Page 368 Common Idioms (Explicit)......Page 369 Basics......Page 371 Computed Attributes......Page 372 Classes that Act Like Functions......Page 375 Classes that Act Like Sequences......Page 376 Classes that Act Like Dictionaries......Page 378 Classes that Act Like Numbers......Page 379 Classes that Can Be Compared......Page 383 Classes that Can Be Used in a “with” Block......Page 384 Really Esoteric Stuff......Page 386 Further Reading Online......Page 387 APPENDIX C Where to Go From Here ......Page 388 Index......Page 390
Similar books
MySQL® Notes for Professionals book
2018 · PDF
MrExcel 2022: Boosting Excel
2022 · PDF
MrExcel 2022: Boosting Excel
2022 · PDF
Session C11: Ancient Cultural Landscapes in South Europe – their Ecological Setting and Evolution, Session C22: Gardeners from South America, Session S04: Agro-Pastoralism and Early Metallurgy Sessions, Session WS29: The Idea of Enclosure in Recent Iberian Prehistory, Session C88: Rhytmes et causalites des dynamiques de l'anthropisation en Europe entre 6500 ET 500 BC: Hypotheses socio-culturelles et/ou climatiques: Proceedings of the XV UISPP World Congress (Lisbon 4-9 September 2006) / Actes du XV Congrès Mondial (Lisbonne 4-9 Septembre 2006) Vol.36
2010 · PDF
THE BRITISH ARMY IN INDIA: ITS PRESERVATION BY AN APPROPRIATE CLOTHING, HOUSING, LOCATING, RECREATIVE EMPLOYMENT, AND HOPEFUL ENCOURAGEMENT OF THE TROOPS. with AN APPENDIX ON INDIA : THE CLIMATE OP ITS HILLS ; THE DEVELOPMENT OF ITS RESODRCBS, INDUSTRY, AND ARTS ; THE ADMINISTRATION OF JUSTICE ; THE BLACK ACT ; THE PROGRESS OF CHRISTIANITY ; THE TRAFFIC IN OPIUM ; THE VALUE OF INDIA ; PERMANENT CAUSES OF DISAFFECTION, AND OF THE RECENT REBELLION ; THE TRADITIONARY POLICY; MISGOVERNMENT BY NATIVE RULERS ; ANNEXATIONS OF THEIR TERRITORY, ETC.
1858 · PDF
Idries Shah 27 Books Collection : A Perfumed Scorpion, A Veiled Gazelle, Caravan of Dreams, Darkest England, Destination Mecca, Evenings with Idries Shah, Knowing How to Know, Learning How to Learn, Letters and Lectures of Idries Shah, Neglected aspects of Sufi study, Observations, Oriental Magic, Reflections, Seeker after Truth, Special Illumination, Special Problems in the study of Sufi ideas, Sufi thought and action, Tales of the Dervishes, The Dermis Probe, The Elephant in the Dark, The Englishman Handbook, Idries Shah Antology, The Magic Monastery, The natives are restless, wisdom of the Idiots PDF.
2022 · PDF
The travels of Capts. Lewis and Clarke from St. Louis, by way of the Missouri and Columbia rivers, to the Pacific ocean; performed in the years 1804, 1805 & 1806, by order of the government of the United States. Containing delineations of the manners, customs, religion, &c. of the Indians, comp. from various authentic sources, and original documents, and a summary of the Statistical view of the Indian nations, from the official communication of Meriwether Lewis. Illustrated with a map of the country, inhabited by the western tribes of Indians
1809 · PDF
Professional Linux kernel architecture ''Wrox programmer to programmer''--Cover. - ''What you are reading right now is the result of an evolution over more than seven years: After two years of writing, the first edition was published in German by Carl Hanser Verlag in 2003. It then described kernel 2.6.0. The test was used as a basis for the low-level design documentation for the EAL4+ security evaluation of Red Hat Enterprise Linux 5, requiring to update it to kernel 2.6.18 (if the EAL acronym does not mean anything to you, then Wikipedia is once more your friend). Hewlett-Packard sponsored the translation into English and has, thankfully, granted the rights to publish the result. Updates to kernel 2.6.24 were then performed specifically for this book''--P. ix
2008 · PDF