General note |
Includes appendix & index <br/>Table of Contents (Summary)<br/>1 The Basics: Getting Started Quickly 1<br/>2 List Data: Working with Ordered Data 47<br/>3 Structured Data: Working with Structured Data 95<br/>4 Code Reuse: Functions and Modules 145<br/>5 Building a Webapp: Getting Real 195<br/>6 Storing and Manipulating Data: Where to Put Your Data 243<br/>7 Using a Database: Putting Python’s DB-API to Use 281<br/>8 A Little Bit of Class: Abstracting Behavior and State 309<br/>9 The Context Management Protocol: Hooking into Python’s with Statement 335<br/>10 Function Decorators: Wrapping Functions 363<br/>11 Exception Handling: What to Do When Things Go Wrong 413<br/>11¾ A Little Bit of Threading: Dealing with Waiting 461<br/>12 Advanced Iteration: Looping like Crazy 477<br/>A Installing: Installing Python 521<br/>B Pythonanywhere: Deploying Your Webapp 529<br/>C Top Ten Things We Didn’t Cover: There’s Always More to Learn 539<br/>D Top Ten Projects Not Covered: Even More Tools, Libraries, and Modules 551<br/>E Getting Involved: The Python Community 563<br/>Table of Contents (the real thing)<br/>Your brain on Python. Here you are trying to learn something, while here<br/>your brain is, doing you a favor by making sure the learning doesn’t stick. Your brain’s<br/>thinking, “Better leave room for more important things, like which wild animals to<br/>avoid and whether naked snowboarding is a bad idea.” So how do you trick your brain<br/>into thinking that your life depends on knowing how to program in Python?<br/>Intro<br/>Who is this book for? xxviii<br/>We know what you’re thinking xxix<br/>We know what your brain is thinking xxix<br/>Metacognition: thinking about thinking xxxi<br/>Here’s what WE did xxxii<br/>Read me xxxiv<br/>Acknowledgments xxxvii<br/>table of contents<br/>x<br/>the basics<br/>Getting Started Quickly<br/>Get going with Python programming as quickly as possible.<br/>In this chapter, we introduce the basics of programming in Python, and we do this in<br/>typical Head First style: by jumping right in. After just a few pages, you’ll have run<br/>your first sample program. By the end of the chapter, you’ll not only be able to run the<br/>sample program, but you’ll understand its code too (and more besides). Along the way,<br/>you’ll learn about a few of the things that make Python the programming language it is.<br/>Understanding IDLE’s Windows 4<br/>Executing Code, One Statement at a Time 8<br/>Functions + Modules = The Standard Library 9<br/>Data Structures Come Built-in 13<br/>Invoking Methods Obtains Results 14<br/>Deciding When to Run Blocks of Code 15<br/>What “else” Can You Have with “if ”? 17<br/>Suites Can Contain Embedded Suites 18<br/>Returning to the Python Shell 22<br/>Experimenting at the Shell 23<br/>Iterating Over a Sequence of Objects 24<br/>Iterating a Specific Number of Times 25<br/>Applying the Outcome of Task #1 to Our Code 26<br/>Arranging to Pause Execution 28<br/>Generating Random Integers with Python 30<br/>Coding a Serious Business Application 38<br/>Is Indentation Driving You Crazy? 40<br/>Asking the Interpreter for Help on a Function 41<br/>Experimenting with Ranges 42<br/>Chapter 1’s Code 46<br/>1<br/>table of contents<br/>xi<br/>list data<br/>Working with Data<br/>All programs process data, and Python programs are no exception.<br/>In fact, take a look around: data is everywhere. A lot of, if not most, programming is all about<br/>data: acquiring data, processing data, understanding data. To work with data effectively, you need<br/>somewhere to put your data when processing it. Python shines in this regard, thanks (in no small<br/>part) to its inclusion of a handful of widely applicable data structures: lists, dictionaries, tuples, and<br/>sets. In this chapter, we’ll preview all four, before spending the majority of this chapter digging deeper<br/>into lists (and we’ll deep-dive into the other three in the next chapter). We’re covering these data<br/>structures early, as most of what you’ll likely do with Python will revolve around working with data.<br/>0<br/>D<br/>-12<br/>1<br/>o<br/>-11<br/>2<br/>n<br/>-10<br/>3<br/>'<br/>-9<br/>4<br/>t<br/>-8<br/>5<br/>-7<br/>6<br/>p<br/>-6<br/>7<br/>a<br/>-5<br/>8<br/>n<br/>-4<br/>9<br/>i<br/>-3<br/>10<br/>c<br/>-2<br/>11<br/>!<br/>-1<br/>Numbers, Strings...and Objects 48<br/>Meet the Four Built-in Data Structures 50<br/>An Unordered Data Structure: Dictionary 52<br/>A Data Structure That Avoids Duplicates: Set 53<br/>Creating Lists Literally 55<br/>Use Your Editor When Working on More Than a Few Lines of Code 57<br/>“Growing” a List at Runtime 58<br/>Checking for Membership with “in” 59<br/>Removing Objects from a List 62<br/>Extending a List with Objects 64<br/>Inserting an Object into a List 65<br/>How to Copy a Data Structure 73<br/>Lists Extend the Square Bracket Notation 75<br/>Lists Understand Start, Stop, and Step 76<br/>Starting and Stopping with Lists 78<br/>Putting Slices to Work on Lists 80<br/>Python’s “for” Loop Understands Lists 86<br/>Marvin’s Slices in Detail 88<br/>When Not to Use Lists 91<br/>Chapter 2’s Code, 1 of 2 92<br/>2<br/>table of contents<br/>xii<br/>Name: Ford Prefect<br/>Gender: Male<br/>Occupation: Researcher<br/>Home Planet: Betelgeuse Seven<br/>structured data<br/>Working with Structured Data<br/>Python’s list data structure is great, but it isn’t a data<br/>panacea. When you have truly structured data (and using a list to store it may not be<br/>the best choice), Python comes to your rescue with its built-in dictionary. Out of the box,<br/>the dictionary lets you store and manipulate any collection of key/value pairs. We look<br/>long and hard at Python’s dictionary in this chapter, and—along the way—meet set and<br/>tuple, too. Together with the list (which we met in the previous chapter), the dictionary,<br/>set, and tuple data structures provide a set of built-in data tools that help to make Python<br/>and data a powerful combination.<br/>A Dictionary Stores Key/Value Pairs 96<br/>How to Spot a Dictionary in Code 98<br/>Insertion Order Is NOT Maintained 99<br/>Value Lookup with Square Brackets 100<br/>Working with Dictionaries at Runtime 101<br/>Updating a Frequency Counter 105<br/>Iterating Over a Dictionary 107<br/>Iterating Over Keys and Values 108<br/>Iterating Over a Dictionary with “items” 110<br/>Just How Dynamic Are Dictionaries? 114<br/>Avoiding KeyErrors at Runtime 116<br/>Checking for Membership with “in” 117<br/>Ensuring Initialization Before Use 118<br/>Substituting “not in” for “in” 119<br/>Putting the “setdefault” Method to Work 120<br/>Creating Sets Efficiently 124<br/>Taking Advantage of Set Methods 125<br/>Making the Case for Tuples 132<br/>Combining the Built-in Data Structures 135<br/>Accessing a Complex Data Structure’s Data 141<br/>Chapter 3’s Code, 1 of 2 143<br/>3<br/>table of contents<br/>xiii<br/>module<br/>code reuse<br/>Functions and Modules<br/>Reusing code is key to building a maintainable system.<br/>And when it comes to reusing code in Python, it all starts and ends with the humble<br/>function. Take some lines of code, give them a name, and you’ve got a function (which<br/>can be reused). Take a collection of functions and package them as a file, and you’ve<br/>got a module (which can also be reused). It’s true what they say: it’s good to share, and<br/>by the end of this chapter, you’ll be well on your way to sharing and reusing your code,<br/>thanks to an understanding of how Python’s functions and modules work.<br/>Reusing Code with Functions 146<br/>Introducing Functions 147<br/>Invoking Your Function 150<br/>Functions Can Accept Arguments 154<br/>Returning One Value 158<br/>Returning More Than One Value 159<br/>Recalling the Built-in Data Structures 161<br/>Making a Generically Useful Function 165<br/>Creating Another Function, 1 of 3 166<br/>Specifying Default Values for Arguments 170<br/>Positional Versus Keyword Assignment 171<br/>Updating What We Know About Functions 172<br/>Running Python from the Command Line 175<br/>Creating the Required Setup Files 179<br/>Creating the Distribution File 180<br/>Installing Packages with “pip” 182<br/>Demonstrating Call-by-Value Semantics 185<br/>Demonstrating Call-by-Reference Semantics 186<br/>Install the Testing Developer Tools 190<br/>How PEP 8–Compliant Is Our Code? 191<br/>Understanding the Failure Messages 192<br/>Chapter 4’s Programs 194<br/>4<br/>table of contents<br/>xiv<br/>building a webapp<br/>Getting Real<br/>At this stage, you know enough Python to be dangerous.<br/>With this book’s first four chapters behind you, you’re now in a position to productively<br/>use Python within any number of application areas (even though there’s still lots of<br/>Python to learn). Rather than explore the long list of what these application areas<br/>are, in this and subsequent chapters, we’re going to structure our learning around the<br/>development of a web-hosted application, which is an area where Python is especially<br/>strong. Along the way, you’ll learn a bit more about Python.<br/>Python: What You Already Know 196<br/>What Do We Want Our Webapp to Do? 200<br/>Let’s Install Flask 202<br/>How Does Flask Work? 203<br/>Running Your Flask Webapp for the First Time 204<br/>Creating a Flask Webapp Object 206<br/>Decorating a Function with a URL 207<br/>Running Your Webapp’s Behavior(s) 208<br/>Exposing Functionality to the Web 209<br/>Building the HTML Form 213<br/>Templates Relate to Web Pages 216<br/>Rendering Templates from Flask 217<br/>Displaying the Webapp’s HTML Form 218<br/>Preparing to Run the Template Code 219<br/>Understanding HTTP Status Codes 222<br/>Handling Posted Data 223<br/>Refining the Edit/Stop/Start/Test Cycle 224<br/>Accessing HTML Form Data with Flask 226<br/>Using Request Data in Your Webapp 227<br/>Producing the Results As HTML 229<br/>Preparing Your Webapp for the Cloud 238<br/>Chapter 5’s Code 241<br/>5<br/>table of contents<br/>xv<br/> Form Data Remote_addr User_agent Results<br/>ImmutableMultiDict([(‘phrase’, 127.0.0.1 Mozilla/5.0 (Macintosh; {‘e’, ‘i’}<br/>‘hitch-hiker’), (‘letters’, ‘aeiou’)]) Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML,<br/>like Gecko) Chrome/47.0.2526<br/>.106 Safari/537.36<br/>storing and manipulating data<br/>Where to Put Your Data<br/>Sooner or later, you’ll need to safely store your data somewhere.<br/>And when it comes to storing data, Python has you covered. In this chapter, you’ll learn<br/>about storing and retrieving data from text files, which—as storage mechanisms go—may<br/>feel a bit simplistic, but is nevertheless used in many problem areas. As well as storing and<br/>retrieving your data from files, you’ll also learn some tricks of the trade when it comes to<br/>manipulating data. We’re saving the “serious stuff” (storing data in a database) until the next<br/>chapter, but there’s plenty to keep us busy for now when working with files.<br/>Doing Something with Your Webapp’s Data 244<br/>Python Supports Open, Process, Close 245<br/>Reading Data from an Existing File 246<br/>A Better Open, Process, Close: “with” 248<br/>View the Log Through Your Webapp 254<br/>Examine the Raw Data with View Source 256<br/>It’s Time to Escape (Your Data) 257<br/>Viewing the Entire Log in Your Webapp 258<br/>Logging Specific Web Request Attributes 261<br/>Log a Single Line of Delimited Data 262<br/>From Raw Data to Readable Output 265<br/>Generate Readable Output With HTML 274<br/>Embed Display Logic in Your Template 275<br/>Producing Readable Output with Jinja2 276<br/>The Current State of Our Webapp Code 278<br/>Asking Questions of Your Data 279<br/>Chapter 6’s Code 280<br/>6<br/>table of contents<br/>xvi<br/>Python’s<br/>DB-API<br/>The MySQLConnector/Python<br/>Driver<br/>MySQL Your code<br/>using a database<br/>Putting Python’s DB-API to Use<br/>Storing data in a relational database system is handy. In this chapter,<br/>you’ll learn how to write code that interacts with the popular MySQL database technology, using<br/>a generic database API called DB-API. The DB-API (which comes standard with every Python<br/>install) allows you to write code that is easily transferred from one database product to the next...<br/>assuming your database talks SQL. Although we’ll be using MySQL, there’s nothing stopping you<br/>from using your DB-API code with your favorite relational database, whatever it may be. Let’s<br/>see what’s involved in using a relational database with Python. There’s not a lot of new Python in<br/>this chapter, but using Python to talk to databases is a big deal, so it’s well worth learning.<br/>Database-Enabling Your Webapp 282<br/>Task 1: Install the MySQL Server 283<br/>Introducing Python’s DB-API 284<br/>Task 2: Install a MySQL Database Driver for Python 285<br/>Install MySQL-Connector/Python 286<br/>Task 3: Create Our Webapp’s Database and Tables 287<br/>Decide on a Structure for Your Log Data 288<br/>Confirm Your Table Is Ready for Data 289<br/>Task 4: Create Code to Work with Our Webapp’s Database and Tables 296<br/>Storing Data Is Only Half the Battle 300<br/>How Best to Reuse Your Database Code? 301<br/>Consider What You’re Trying to Reuse 302<br/>What About That Import? 303<br/>You’ve Seen This Pattern Before 305<br/>The Bad News Isn’t Really All That Bad 306<br/>Chapter 7’s Code 307<br/>7<br/>table of contents<br/>xvii<br/>a little bit of class<br/>Abstracting Behavior and State<br/>Classes let you bundle code behavior and state together.<br/>In this chapter, you’re setting your webapp aside while you learn about creating Python classes.<br/>You’re doing this in order to get to the point where you can create a context manager with the<br/>help of a Python class. As creating and using classes is such a useful thing to know about<br/>anyway, we’re dedicating this chapter to them. We won’t cover everything about classes, but we’ll<br/>touch on all the bits you’ll need to understand in order to confidently create the context manager<br/>your webapp is waiting for.<br/>Hooking into the “with” Statement 310<br/>An Object-Oriented Primer 311<br/>Creating Objects from Classes 312<br/>Objects Share Behavior but Not State 313<br/>Doing More with CountFromBy 314<br/>Invoking a Method: Understand the Details 316<br/>Adding a Method to a Class 318<br/>The Importance of “self ” 320<br/>Coping with Scoping 321<br/>Prefix Your Attribute Names with “self ” 322<br/>Initialize (Attribute) Values Before Use 323<br/>Dunder “init” Initializes Attributes 324<br/>Initializing Attributes with Dunder “init” 325<br/>Understanding CountFromBy’s Representation 328<br/>Defining CountFromBy’s Representation 329<br/>Providing Sensible Defaults for CountFromBy 330<br/>Classes: What We Know 332<br/>Chapter 8’s Code 333<br/>8<br/>table of contents<br/>xviii<br/>§<br/>$ mysql -u vsearch -p vsearchlogDB<br/>Enter password:<br/>Welcome to MySQL monitor...<br/>mysql> select * from log;<br/>+----+---------------------+--------------------------+---------+-----------+----------------+----------------------+<br/>| id | ts | phrase | letters | ip | browser_string | results |<br/>+----+---------------------+--------------------------+---------+-----------+----------------+----------------------+<br/>| 1 | 2016-03-09 13:40:46 | life, the uni ... ything | aeiou | 127.0.0.1 | firefox | {'u', 'e', 'i', 'a'} |<br/>| 2 | 2016-03-09 13:42:07 | hitch-hiker | aeiou | 127.0.0.1 | safari | {'i', 'e'} |<br/>| 3 | 2016-03-09 13:42:15 | galaxy | xyz | 127.0.0.1 | chrome | {'y', 'x'} |<br/>| 4 | 2016-03-09 13:43:07 | hitch-hiker | xyz | 127.0.0.1 | firefox | set() |<br/>+----+---------------------+--------------------------+---------+-----------+----------------+----------------------+<br/>4 rows in set (0.0 sec)<br/>mysql> quit<br/>Bye<br/>File Edit Window Help Checking our log DB<br/>the context management protocol<br/>Hooking into Python’s with Statements<br/>It’s time to take what you’ve just learned and put it to work.<br/>Chapter 7 discussed using a relational database with Python, while Chapter 8 provided an<br/>introduction to using classes in your Python code. In this chapter, both of these techniques are<br/>combined to produce a context manager that lets us extend the with statement to work with<br/>relational database systems. In this chapter, you’ll hook into the with statement by creating a<br/>new class, which conforms to Python’s context management protocol.<br/>What’s the Best Way to Share Our Webapp’s Database Code? 336<br/>Managing Context with Methods 338<br/>You’ve Already Seen a Context Manager in Action 339<br/>Create a New Context Manager Class 340<br/>Initialize the Class with the Database Config 341<br/>Perform Setup with Dunder “enter” 343<br/>Perform Teardown with Dunder “exit” 345<br/>Reconsidering Your Webapp Code, 1 of 2 348<br/>Recalling the “log_request” Function 350<br/>Amending the “log_request” Function 351<br/>Recalling the “view_the_log” Function 352<br/>It’s Not Just the Code That Changes 353<br/>Amending the “view_the_log” Function 354<br/>Answering the Data Questions 359<br/>Chapter 9’s Code, 1 of 2 360<br/>9<br/>table of contents<br/>xix<br/>function decorators<br/>Wrapping Functions<br/>When it comes to augmenting your code, Chapter 9’s context<br/>management protocol is not the only game in town. Python also lets you<br/>use function decorators, a technique whereby you can add code to an existing function without<br/>having to change any of the existing function’s code. If you think this sounds like some sort of<br/>black art, don’t despair: it’s nothing of the sort. However, as coding techniques go, creating a<br/>function decorator is often considered to be on the harder side by many Python programmers,<br/>and thus is not used as often as it should be. In this chapter, our plan is to show you that, despite<br/>being an advanced technique, creating and using your own decorators is not that hard.<br/>Your Web Server (Not Your Computer) Runs Your Code 366<br/>Flask’s Session Technology Adds State 368<br/>Dictionary Lookup Retrieves State 369<br/>Managing Logins with Sessions 374<br/>Let’s Do Logout and Status Checking 377<br/>Pass a Function to a Function 386<br/>Invoking a Passed Function 387<br/>Accepting a List of Arguments 390<br/>Processing a List of Arguments 391<br/>Accepting a Dictionary of Arguments 392<br/>Processing a Dictionary of Arguments 393<br/>Accepting Any Number and Type of Function Arguments 394<br/>Creating a Function Decorator 397<br/>The Final Step: Handling Arguments 401<br/>Putting Your Decorator to Work 404<br/>Back to Restricting Access to /viewlog 408<br/>Chapter 10’s Code, 1 of 2 410<br/>10<br/>table of contents<br/>xx<br/> ...<br/>Exception<br/> +-- StopIteration<br/> +-- StopAsyncIteration<br/> +-- ArithmeticError<br/> | +-- FloatingPointError<br/> | +-- OverflowError<br/> | +-- ZeroDivisionError<br/> +-- AssertionError<br/> +-- AttributeError<br/> +-- BufferError<br/> +-- EOFError<br/>...<br/>exception handling<br/>What to Do When Things Go Wrong<br/>Things go wrong, all the time—no matter how good your code is.<br/>You’ve successfully executed all of the examples in this book, and you’re likely confident all of<br/>the code presented thus far works. But does this mean the code is robust? Probably not. Writing<br/>code based on the assumption that nothing bad ever happens is (at best) naive. At worst, it’s<br/>dangerous, as unforeseen things do (and will) happen. It’s much better if you’re wary while<br/>coding, as opposed to trusting. Care is needed to ensure your code does what you want it to, as<br/>well as reacts properly when things go south.<br/>Databases Aren’t Always Available 418<br/>Web Attacks Are a Real Pain 419<br/>Input-Output Is (Sometimes) Slow 420<br/>Your Function Calls Can Fail 421<br/>Always Try to Execute Error-Prone Code 423<br/>try Once, but except Many Times 426<br/>The Catch-All Exception Handler 428<br/>Learning About Exceptions from “sys” 430<br/>The Catch-All Exception Handler, Revisited 431<br/>Getting Back to Our Webapp Code 433<br/>Silently Handling Exceptions 434<br/>Handling Other Database Errors 440<br/>Avoid Tightly Coupled Code 442<br/>The DBcm Module, Revisited 443<br/>Creating Custom Exceptions 444<br/>What Else Can Go Wrong with “DBcm”? 448<br/>Handling SQLError Is Different 451<br/>Raising an SQLError 453<br/>A Quick Recap: Adding Robustness 455<br/>How to Deal with Wait? It Depends... 456<br/>Chapter 11’s Code, 1 of 3 457<br/>11<br/>table of contents<br/>xxi<br/>Wait!<br/>a little bit of threading<br/>Dealing with Waiting<br/>Your code can sometimes take a long time to execute.<br/>Depending on who notices, this may or may not be an issue. If some code takes 30<br/>seconds to do its thing “behind the scenes,” the wait may not be an issue. However,<br/>if your user is waiting for your application to respond, and it takes 30 seconds,<br/>everyone notices. What you should do to fix this problem depends on what you’re<br/>trying to do (and who’s doing the waiting). In this short chapter, we’ll briefly discuss<br/>some options, then look at one solution to the issue at hand: what happens if<br/>something takes too long?<br/>Waiting: What to Do? 462<br/>How Are You Querying Your Database? 463<br/>Database INSERTs and SELECTs Are Different 464<br/>Doing More Than One Thing at Once 465<br/>Don’t Get Bummed Out: Use Threads 466<br/>First Things First: Don’t Panic 470<br/>Don’t Get Bummed Out: Flask Can Help 471<br/>Is Your Webapp Robust Now? 474<br/>Chapter 11¾’s Code, 1 of 2 475<br/>113<br/>/4<br/>table of contents<br/>xxii<br/>advanced iteration<br/>Looping Like Crazy<br/>It’s often amazing how much time our programs spend in loops.<br/>This isn’t a surprise, as most programs exist to perform something quickly a whole heap of times.<br/>When it comes to optimizing loops, there are two approaches: (1) improve the loop syntax (to<br/>make it easier to specify a loop), and (2) improve how loops execute (to make them go faster).<br/>Early in the lifetime of Python 2 (that is, a long, long time ago), the language designers added a<br/>single language feature that implements both approaches, and it goes by a rather strange name:<br/>comprehension.<br/>Reading CSV Data As Lists 479<br/>Reading CSV Data As Dictionaries 480<br/>Stripping, Then Splitting, Your Raw Data 482<br/>Be Careful When Chaining Method Calls 483<br/>Transforming Data into the Format You Need 484<br/>Transforming into a Dictionary Of Lists 485<br/>Spotting the Pattern with Lists 490<br/>Converting Patterns into Comprehensions 491<br/>Take a Closer Look at the Comprehension 492<br/>Specifying a Dictionary Comprehension 494<br/>Extend Comprehensions with Filters 495<br/>Deal with Complexity the Python Way 499<br/>The Set Comprehension in Action 505<br/>What About “Tuple Comprehensions”? 507<br/>Parentheses Around Code == Generator 508<br/>Using a Listcomp to Process URLs 509<br/>Using a Generator to Process URLs 510<br/>Define What Your Function Needs to Do 512<br/>Yield to the Power of Generator Functions 513<br/>Tracing Your Generator Function, 1 of 2 514<br/>One Final Question 518<br/>Chapter 12’s Code 519<br/>It’s Time to Go… 520<br/>12<br/>table of contents<br/>xxiii<br/>installation<br/>Installing Python<br/>pythonanywhere<br/>Deploying Your Webapp<br/>First things first: let’s get Python installed on your computer.<br/>Whether you’re running on Windows, Mac OS X, or Linux, Python’s got you covered. How you<br/>install it on each of these platforms is specific to how things work on each of these operating<br/>systems (we know...a shocker, eh?), and the Python community works hard to provide installers<br/>that target all the popular systems. In this short appendix, you’ll be guided through installing<br/>Python on your computer.<br/>At the end of Chapter 5, we claimed that deploying your webapp to<br/>the cloud was only 10 minutes away. It’s now time to make good on that promise.<br/>In this appendix, we are going to take you through the process of deploying your webapp on<br/>PythonAnywhere, going from zero to deployed in about 10 minutes. PythonAnywhere is a<br/>favorite among the Python programming community, and it’s not hard to see why: it works exactly<br/>as you’d expect it to, has great support for Python (and Flask), and—best of all—you can get<br/>started hosting your webapp at no cost.<br/>Install Python 3 on Windows 522<br/>Check Python 3 on Windows 523<br/>Add to Python 3 on Windows 524<br/>Install Python 3 on Mac OS X (macOS) 525<br/>Check and Configure Python 3 on Mac OS X 526<br/>Install Python 3 on Linux 527<br/>Step 0: A Little Prep 530<br/>Step 1: Sign Up for PythonAnywhere 531<br/>Step 2: Upload Your Files to the Cloud 532<br/>Step 3: Extract and Install Your Code 533<br/>Step 4: Create a Starter Webapp, 1 of 2 534<br/>Step 5: Configure Your Webapp 536<br/>Step 6: Take Your Cloud-Based Webapp for a Spin! 537<br/>a<br/>b<br/>table of contents<br/>xxiv<br/>top ten things we didn’t cover<br/>There’s Always More to Learn<br/>It was never our intention to try to cover everything. This book’s goal was<br/>always to show you enough Python to get you up to speed as quickly as possible. There’s a lot<br/>more we could’ve covered, but didn’t. In this appendix, we discuss the top 10 things that—given<br/>another 600 pages or so—we would’ve eventually gotten around to. Not all of the 10 things will<br/>interest you, but quickly flip through them just in case we’ve hit on your sweet spot, or provided<br/>an answer to that nagging question. All the programming technologies in this appendix come<br/>baked in to Python and its interpreter.<br/>1. What About Python 2? 540<br/>2. Virtual Programming Environments 541<br/>3. More on Object Orientation 542<br/>4. Formats for Strings and the Like 543<br/>5. Getting Things Sorted 544<br/>6. More from the Standard Library 545<br/>7. Running Your Code Concurrently 546<br/>8. GUIs with Tkinter (and Fun with Turtles) 547<br/>9. It’s Not Over ’Til It’s Tested 548<br/>10. Debug, Debug, Debug 549<br/>c<br/>table of contents<br/>xxv<br/>top ten projects not covered<br/>Even More Tools, Libraries, and Modules<br/>We know what you’re thinking as you read this appendix’s title.<br/>Why on Earth didn’t they make the title of the last appendix: The Top Twenty Things We Didn’t<br/>Cover? Why another 10? In the last appendix, we limited our discussion to stuff that comes<br/>baked in to Python (part of the language’s “batteries included”). In this appendix, we cast the net<br/>much further afield, discussing a whole host of technologies that are available to you because<br/>Python exists. There’s lots of good stuff here and—just like with the last appendix—a quick<br/>perusal won’t hurt you one single bit.<br/>1. Alternatives to >>> 552<br/>2. Alternatives to IDLE 553<br/>3. Jupyter Notebook: The Web-Based IDE 554<br/>4. Doing Data Science 555<br/>5. Web Development Technologies 556<br/>6. Working with Web Data 557<br/>7. More Data Sources 558<br/>8. Programming Tools 559<br/>9. Kivy: Our Pick for “Coolest Project Ever” 560<br/>10. Alternative Implementations 561<br/>d<br/>table of contents<br/>xxvi<br/>getting involved<br/>The Python Community<br/>Python is much more than a great programming language.<br/>It’s a great community, too. The Python Community is welcoming, diverse, open, friendly,<br/>sharing, and giving. We’re just amazed that no one, to date, has thought to put that on a<br/>greeting card! Seriously, though, there’s more to programming in Python than the language. An<br/>entire ecosystem has grown up around Python, in the form of excellent books, blogs, websites,<br/>conferences, meetups, user groups, and personalities. In this appendix, we take a survey of the<br/>Python community and see what it has to offer. Don’t just sit around programming on your own:<br/>get involved!<br/>BDFL: Benevolent Dictator for Life 564<br/>A Tolerant Community: Respect for Diversity 565<br/>Python Podcasts 566<br/>The Zen of Python 567<br/>Which Book Should I Read Next? 568<br/>Our Favorite Python Books 569<br/> |