Book description
Add Python to your programming skills and have some fun at the same time. Head First Python takes you beyond typical how-to manuals with an engaging visual format that includes images, puzzles, stories, and quizzes that are proven to stimulate learning and retention. You'll not only learn how Python differs from other programming languages and how it's similar, you'll learn how to be a great programmer.
Table of contents
- Dedication
- Special Upgrade Offer
- A Note Regarding Supplemental Files
- Advance Praise for Head First Python
- Praise for other Head First books
- Author of Head First Python
- How to use This Book: Intro
-
1. Meet Python: Everyone loves lists
- What’s to like about Python?
- Install Python 3
- Use IDLE to help learn Python
- Work effectively with IDLE
- Deal with complex data
- Create simple Python lists
- Lists are like arrays
- Add more data to your list
- Work with your list data
- For loops work with lists of any size
- Store lists within lists
- Check a list for a list
- Complex data is hard to process
- Handle many levels of nested lists
- Don’t repeat code; create a function
- Create a function in Python
- Recursion to the rescue!
- Your Python Toolbox
-
2. Sharing your Code: Modules of functions
- It’s too good not to share
- Turn your function into a module
- Modules are everywhere
- Comment your code
- Prepare your distribution
- Build your distribution
- A quick review of your distribution
- Import a module to use it
- Python’s modules implement namespaces
- Register with the PyPI website
- Upload your code to PyPI
- Welcome to the PyPI community
- With success comes responsibility
- Life’s full of choices
- Control behavior with an extra argument
- Before your write new code, think BIF
- Python tries its best to run your code
- Trace your code
- Work out what’s wrong
- Update PyPI with your new code
- You’ve changed your API
- Use optional arguments
- Your module supports both APIs
- Your API is still not right
- Your module’s reputation is restored
- Your Python Toolbox
-
3. Files and Exceptions: Dealing with errors
- Data is external to your program
- It’s all lines of text
- Take a closer look at the data
- Know your data
- Know your methods and ask for help
- Know your data (better)
- Two very different approaches
- Add extra logic
- Handle exceptions
- Try first, then recover
- Identify the code to protect
- Take a pass on the error
- What about other errors?
- Add more error-checking code...
- ...Or add another level of exception handling
- So, which approach is best?
- You’re done...except for one small thing
- Be specific with your exceptions
- Your Python Toolbox
-
4. Persistence: Saving data to files
- Programs produce data
- Open your file in write mode
- Files are left open after an exception!
- Extend try with finally
- Knowing the type of error is not enough
- Use with to work with files
- Default formats are unsuitable for files
- Why not modify print_lol()?
- Pickle your data
- Save with dump and restore with load
- Generic file I/O with pickle is the way to go!
- Your Python Toolbox
- 5. Comprehending data: Work that data!
-
6. Custom data Objects: Bundling code with data
- Coach Kelly is back (with a new file format)
- Use a dictionary to associate data
- Bundle your code and its data in a class
- Define a class
- Use class to define classes
- The importance of self
- Every method’s first argument is self
- Inherit from Python’s built-in list
- Coach Kelly is impressed
- Your Python Toolbox
-
7. Web Development: Putting it all together
- It’s good to share
- You can put your program on the Web
- What does your webapp need to do?
- Design your webapp with MVC
- Model your data
- View your interface
- Control your code
- CGI lets your web server run programs
- Display the list of athletes
- The dreaded 404 error!
- Create another CGI script
- Enable CGI tracking to help with errors
- A small change can make all the difference
- Your webapp’s a hit!
- Your Python Toolbox
-
8. Mobile app Development: Small devices
- The world is getting smaller
- Coach Kelly is on Android
- Don’t worry about Python 2
- Set up your development environment
- Configure the SDK and emulator
- Install and configure Android Scripting
- Add Python to your SL4A installation
- Test Python on Android
- Define your app’s requirements
- The SL4A Android API
- Select from a list on Android
- The athlete’s data CGI script
- The data appears to have changed type
- JSON can’t handle your custom datatypes
- Run your app on a real phone
- Configure AndFTP
- The coach is thrilled with his app
- Your Python Toolbox
-
9. Manage Your data: Handling input
- Your athlete times app has gone national
- Use a form or dialog to accept input
- Create an HTML form template
- The data is delivered to your CGI script
- Ask for input on your Android phone
- It’s time to update your server data
- Avoid race conditions
- You need a better data storage mechanism
- Use a database management system
- Python includes SQLite
- Exploit Python’s database API
- The database API as Python code
- A little database design goes a long way
- Define your database schema
- What does the data look like?
- Transfer the data from your pickle to SQLite
- What ID is assigned to which athlete?
- Insert your timing data
- SQLite data management tools
- Integrate SQLite with your existing webapp
- You still need the list of names
- Get an athlete’s details based on ID
- You need to amend your Android app, too
- Update your SQLite-based athlete data
- The NUAC is over the moon!
- Your Python Toolbox
-
10. Scaling your Webapp: Getting real
- There are whale sightings everywhere
- The HFWWG needs to automate
- Build your webapp with Google App Engine
- Download and install App Engine
- Make sure App Engine is working
- App Engine uses the MVC pattern
- Model your data with App Engine
- What good is a model without a view?
- Use templates in App Engine
- Django’s form validation framework
- Check your form
- Controlling your App Engine webapp
- Restrict input by providing options
- Meet the “blank screen of death”
- Process the POST within your webapp
- Put your data in the datastore
- Don’t break the “robustness principle”
- Accept almost any date and time
- It looks like you’re not quite done yet
- Sometimes, the tiniest change can make all the difference...
- Capture your user’s Google ID, too
- Deploy your webapp to Google’s cloud
- Your HFWWG webapp is deployed!
- Your Python Toolbox
-
11. Dealing with Complexity: Data wrangling
- What’s a good time goal for the next race?
- So... what’s the problem?
- Start with the data
- Store each time as a dictionary
- Dissect the prediction code
- Get input from your user
- Getting input raises an issue...
- If it’s not in the dictionary, it can’t be found
- Search for the closest match
- The trouble is with time
- The time-to-seconds-to-time module
- The trouble is still with time...
- Port to Android
- Your Android app is a bunch of dialogs
- Put your app together...
- Your app’s a wrap!
- Your Python Toolbox
- It’s time to go...
- A. Leftovers: The Top Ten Things (we didn’t cover)
- Index
- About the Author
- Special Upgrade Offer
- Copyright
Product information
- Title: Head First Python
- Author(s):
- Release date: November 2010
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781449382674
You might also like
book
Head First Python, 2nd Edition
Want to learn the Python language without slogging your way through how-to manuals? With Head First …
book
Head First Python, 3rd Edition
What will you learn from this book? Want to learn the Python language without slogging your …
book
Dead Simple Python
Dead Simple Python is a thorough introduction to every feature of the Python language for programmers …
book
Learning Python, 5th Edition
Get a comprehensive, in-depth introduction to the core Python language with this hands-on book. Based on …