List of Listings

Chapter 2. Hunt the Wumpus

Listing 2.1. Your first version of Hunt the Wumpus

Listing 2.2. BANG! Your program explodes

Listing 2.3. Adding a friend for the wumpus

Listing 2.4. Setting up your caves

Listing 2.5. Altering your program to use the new cave system

Listing 2.6. Creating a linked cave network

Listing 2.7. Adding convenience functions

Listing 2.8. Cave-creation functions

Listing 2.9. Player-interaction functions

Listing 2.10. The refactored wumpus game

Listing 2.11. Adding arrows

Listing 2.12. An interface for Hunt the Wumpus

Listing 2.13. A list of cave names

Listing 2.14. Hunt the Wumpus—now with 40% more atmosphere!

Chapter 3. Interacting with the world

Listing 3.1. Finding out more about the os.path library

Listing 3.2. Reading parameters using sys

Listing 3.3. Using os.walk()

Listing 3.4. Generating a hash for a file

Listing 3.5. How to use a dictionary

Listing 3.6. Utility functions for your difference program

Listing 3.7. Finding the differences between directories

Listing 3.8. Separating generated results from display

Listing 3.9. Comparing directories, too

Chapter 4. Getting organized

Listing 4.1. Your first unit test

Listing 4.2. One part of the program you can’t test

Listing 4.3. The other part of the program you can’t test

Listing 4.4. Finding command fields

Listing 4.5. Testing run_command

Listing 4.6. Writing run_command

Listing 4.7. Your program so far

Listing 4.8. Testing your to-do list view

Listing 4.9. Displaying to-do items

Listing 4.10. Testing the order of your view

Listing 4.11. Lots of things you can do with list comprehensions

Listing 4.12. Code to sort your list of to-dos

Listing 4.13. Output from your tests

Listing 4.14. A better way to display your to-dos

Listing 4.15. Testing that your to-dos wrap lines

Listing 4.16. A function to show a to-do

Listing 4.17. Testing that your application saves properly

Listing 4.18. Loading and saving your to-dos

Listing 4.19. Automatic loading and saving

Listing 4.20. Adding a to-do sorter

Listing 4.21. New sort_todos

Listing 4.22. Testing deletion

Listing 4.23. Deleting to-dos

Listing 4.24. Testing to-do editing

Listing 4.25. Testing sort order after editing

Listing 4.26. Code to edit a to-do

Chapter 5. Business-oriented programming

Listing 5.1. Downloading a web page

Listing 5.2. Finding the quote section

Listing 5.3. Extracting the data for the stock

Listing 5.4. Writing a CSV file

Listing 5.5. Creating a MIME email

Listing 5.6. Sending an email

Listing 5.7. Queuing email to a temporary file

Listing 5.8. Sending email from a mail queue directory

Listing 5.9. A traceback when sending mail

Listing 5.10. A traceback when parsing an HTML page

Listing 5.11. A mail sender with exception handling

Listing 5.12. Using the traceback module

Chapter 6. Classes and object-oriented programming

Listing 6.1. An object to store caves

Listing 6.2. A more object-oriented design

Listing 6.3. A Player object

Listing 6.4. Running your Player class

Listing 6.5. An object that can be looked at

Listing 6.6. Modifying the look() command

Listing 6.7. Updating your setup

Listing 6.8. Items that will let themselves be picked up

Listing 6.9. Updates to the Player class

Listing 6.10. Adding movement to the Cave class

Listing 6.11. Commands to move between caves

Listing 6.12. Creating a cave network

Listing 6.13. Adding monsters to the game

Listing 6.14. A Game class

Listing 6.15. Attacking other objects

Listing 6.16. Updating your monster’s AI

Chapter 7. Sufficiently advanced technology...

Listing 7.1. A logging mixin

Listing 7.2. Using Python’s logging module

Listing 7.3. Using __getattr__

Listing 7.4. Using __setattr__

Listing 7.5. Using __getattribute__

Listing 7.6. Using properties

Listing 7.7. Extending properties

Listing 7.8. Using an iterator the hard way

Listing 7.9. Using your counter generator

Listing 7.10. os.walk revisited

Listing 7.11. The output from os.walk

Listing 7.12. Generators to work through a directory

Listing 7.13. Apache log lines

Listing 7.14. Parsing Apache log lines

Listing 7.15. Django’s user_passes_test decorator

Chapter 8. Django!

Listing 8.1. Django first run

Listing 8.2. First steps

Listing 8.3. A simple todo list

Listing 8.4. Using a template

Listing 8.5. A simple template

Listing 8.6. Editing settings.py

Listing 8.7. A todo model

Listing 8.8. Adding the todo application to your project

Listing 8.9. Showing your model’s SQL

Listing 8.10. Activating Django’s admin system

Listing 8.11. Registering your model: admin.py

Listing 8.12. Altering your view

Listing 8.13. Readable priorities

Listing 8.14. A RESTful URL design

Listing 8.15. Setting URLs and views

Listing 8.16. A submission form

Listing 8.17. A view to handle adding a todo

Listing 8.18. Updating urls.py

Listing 8.19. A todo editing template

Listing 8.20. A deletion template

Listing 8.21. Editing the index page

Chapter 9. Gaming with Pyglet

Listing 9.1. Drawing on the screen

Listing 9.2. Ship class

Listing 9.3. Handling events

Listing 9.4. Updating the ship

Listing 9.5. Moving the ship

Listing 9.6. Planet updates

Listing 9.7. Figuring out gravity

Listing 9.8. Crashing into the planet

Listing 9.9. Shooting

Listing 9.10. A random alien

Listing 9.11. Making the alien interact

Chapter 10. Twisted networking

Listing 10.1. A simple chat-server protocol

Listing 10.2. Connecting your protocol

Listing 10.3. Updating your chat protocol

Listing 10.4. Updating your chat Factory

Listing 10.5. Changing your game code to work with the new interface

Listing 10.6. Changing the Player code

Listing 10.7. Angry lists

Listing 10.8. Social gaming

Listing 10.9. Updating find_handler

Listing 10.10. Antisocial gaming

Listing 10.11. Mudserver.py

Listing 10.12. Twisted’s AuthenticatingTelnetProtocol class

Listing 10.13. RegisteringTelnetProtocol

Listing 10.14. Loading players

Listing 10.15. Saving players

Listing 10.16. Updating the server

Chapter 11. Django revisited!

Listing 11.1. Django authentication and login views

Listing 11.2. Login template

Listing 11.3. Adding a field to the database backend

Listing 11.4. Showing only your todos

Listing 11.5. Wrapping the update and delete views

Listing 11.6. New urls.py

Listing 11.7. Error messages on the index page

Listing 11.8. Unit testing (tests.py)

Listing 11.9. Functional testing

Listing 11.10. Test run

Listing 11.11. Serving static files with Django

Listing 11.12. A sample Apache mod_python configuration

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

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