售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Learning Python Application Development
Table of Contents
Learning Python Application Development
Credits
Disclaimers
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
Important things to note
Very important note for e-book readers
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Developing Simple Applications
Important housekeeping notes
Installation prerequisites
Installing Python
Option 1 – official distribution
Option 2 – bundled distribution
Python install location
Unix-like operating systems
Windows OS
Verifying Python installation
Installing pip
Installing IPython
Choosing an IDE
The theme of the book
Meet the characters
Simple script – Attack of the Orcs v0.0.1
The game – Attack of the Orcs v0.0.1
Problem statement
Pseudo code – version 0.0.1
Reviewing the code
Running Attack of the Orcs v0.0.1
Using functions – Attack of the Orcs v0.0.5
Revisiting the previous version
Pseudo code with attack feature – Version 0.0.5
Reviewing the code
Running Attack of the Orcs v0.0.5
Using OOP – Attack of the Orcs v1.0.0
Prioritize the feature requests
Problem statement
Redesigning the code
Painting the big picture
Pseudo UML representation
Understanding the pseudo UML diagram
Reviewing the code
Running Attack of the Orcs v1.0.0
Abstract base classes in Python
Exercise
Summary
Very important note for e-book readers
2. Dealing with Exceptions
Revisiting Attack of the Orcs v1.0.0
Debugging the problem
Fixing the bugs…
Exceptions
What is an exception?
Most common exceptions
Exception handling
Raising and re-raising an exception
The else block of try…except
finally...clean it up!
Back to the game – Attack of the Orcs v1.1.0
Preparatory work
Adding the exception handling code
Running Attack of the Orcs v1.1.0
Defining custom exceptions
Preparatory work
Custom exception – The problem
Writing a new exception class
Expanding the exception class
Inheriting from the exception class
Exercise
Summary
3. Modularize, Package, Deploy!
Selecting a versioning convention
Serial increments
Using a date format
Semantic versioning scheme
Modularizing the code
Attack of the Orcs v2.0.0
Creating a package
Importing from the package
Releasing the package on PyPI
Prepare the distribution
Step 1 – Setting up the package directory
Step 2 – Writing the setup.py file
Step 3 – Updating the README and LICENSE.txt files
Step 4 – Updating the MANIFEST.in file
Step 5 – Build a deployment-ready distribution
Uploading the distribution
Step 1 – Creating an account on PyPI test website
Step 2 – Creating a .pypirc file
Step 3 – Register your project
Step 4 – Uploading the package
A single command to do it all
Installing your own distribution
Using a private PyPI repository
Step 1 – Installing pypiserver
Step 2 – Building a new source distribution
Step 3 – Starting a local server
Step 4 – Installing the private distribution
Making an incremental release
Packaging and uploading the new version
Upgrading the installed version
Version controlling the code
Git resources
Installing Git
Configuring your identity
Basic Git terminology
Creating and using a Git repository
Creating a bare remote repository
Clone the repository
Copying the code to the cloned repository
Staging the code and committing
Pushing the changes to the central repository
Using GUI clients for Git
Exercise
Summary
4. Documentation and Best Practices
Documenting the code
Docstrings
Introduction to reStructuredText
Section headings
Paragraphs
Text styles
Code snippets
Mathematical equations
Bullets and numbering
Dosctrings using RST
Docstring formatting styles
Automatically creating docstring stubs
Generating documentation with Sphinx
Step 1 – Installing Sphinx using pip
Step 2 – cd to the source directory
Step 3 – Running sphinx-quickstart
Step 4 – Updating conf.py
Step 5 – Running sphinx-apidoc
Step 6 – Building the documentation
Using sphinx-build
Using Makefile
Python coding standards
Code analysis – How well are we doing?
Code analysis using IDE
Pylint
Pylint in action
PEP8 and AutoPEP8
Exercise
Summary
5. Unit Testing and Refactoring
This is how the chapter is organized
Important housekeeping notes
Why test?
A new feature was requested
You implemented this feature
But something wasn't right...
It required thorough testing
Unit testing
Python unittest framework
Basic terminology
Creating tests with unittest.TestCase
Controlling test execution
Using unittest.TestSuite
Writing unit tests for the application
Setting up a test package
Creating a new class for unit testing
First unit test – Injured unit selection
Running the first unit test
Second unit test – Acquiring the hut
Running only the second test
Creating individual test modules
Batch executing unit tests
Unit tests using mock library
Quick introduction to mock
Let's mock!
Using Mock objects in a unit test
Working with patches
Using patch in a unit test
Third unit test – The play method
Is your code covered?
Resolving import errors, if any
Other unit testing tools
Doctest
Nose
Pytest
Refactoring preamble
Take a detour – Refactor for testability
Refactoring
What is refactoring?
Why refactor?
When to refactor?
How to refactor?
Renaming
Extracting
Moving
Pushing down
Pulling up
Refactoring tools for Python
Unit testing revisited
Refactoring for testability
Fourth unit test – setup_game_scenario
Exercise
Refactoring and redesign exercise
Summary
6. Design Patterns
Introduction to design patterns
Classification of patterns
Behavioral patterns
Creational patterns
Structural patterns
Concurrency patterns
Python language and design patterns
First-class functions
Classes as first-class objects
Closures
Miscellaneous features
Class method
Abstract method
The __getattr__ method
Duck typing
Structure of the rest of the chapter
Fast forward – Attack of the Orcs v6.0.0
Strategy pattern
Strategy scenario – The jump feature
Strategy – The problem
Strategy – Attempted solution
Strategy – Rethinking the design
Strategy solution 1 – Traditional approach
Strategy solution 2 – Pythonic approach
Simple factory
Simple factory scenario – The recruit feature
Simple factory – The problem
Simple factory – Rethinking the design
Simple factory solution 1 – Traditional approach
Simple factory solution 2 – Pythonic approach
Abstract factory pattern
Abstract factory scenario – An accessory store
Abstract factory – The problem
Abstract factory – Rethinking the design
Simplifying the design further
Abstract factory solution – Pythonic approach
Advanced topic – enforcing an interface
Adapter pattern
Adapter scenario – Elf's distant cousin
Adapter – The problem
Adapter – Attempted solution
Adapter solution – Pythonic approach
Adapter – Multiple adapter methods
Summary
7. Performance – Identifying Bottlenecks
Overview of three performance chapters
More focus on the runtime performance
The first performance chapter
The second performance chapter
The third performance chapter
Sneak peek at the upcoming application speedup
Scenario – The Gold Hunt
High-level algorithm
Reviewing the initial code
Running the code
The problem
Identifying the bottlenecks
Measuring the execution time
Measuring the runtime of small code snippets
Code profiling
The cProfile module
The pstats module
The line_profiler package
Memory profiling
The memory_profiler package
Algorithm efficiency and complexity
Algorithm efficiency
Algorithm complexity
Big O notation
Big O complexity classes
O(1) – constant time
O(log n) – logarithmic
O(n) – Linear time
O(n log n) – Log linear
O(n2) – Quadratic
O(n3) – cubic
Upper bound of the complexity
Complexity for common data structures and algorithms
Wrapping up the big O discussion
Summary
8. Improving Performance – Part One
Prerequisite for the chapter
This is how the chapter is organized
Revisiting the Gold Hunt scenario
Selecting a problem size
Profiling the initial code
Optimizing Gold Hunt – Part one
Tweaking the algorithm – The square root
Gold Hunt optimization – Pass one
Skipping the dots
Gold Hunt optimization – Pass two
Using local scope
Gold Hunt optimization – Pass three
Performance improvement goodies
List comprehension
Recording execution time
Dictionary comprehension
Swapping conditional block and for loops
'try' it out in a loop
Choosing the right data structures
The collections module
The deque class
The defaultdict class
Generators and generator expressions
Generator expressions
Comparing the memory efficiency
Generator expressions or list comprehensions?
The itertools module
The itertools.chain iterator
Exercises
Summary
9. Improving Performance – Part Two, NumPy and Parallelization
Prerequisites for this chapter
This is how the chapter is organized
Introduction to NumPy
Installing NumPy
Creating array objects
Simple array operations
Array slicing and indexing
Indexing
Slicing
Broadcasting
Miscellaneous functions
numpy.ndarray.tolist
numpy.reshape
numpy.random
numpy.dstack
numpy.einsum
Computing distance square with einsum
Where to get more information on NumPy?
Optimizing Gold Hunt – Part two
Gold Hunt optimization – pass four
Gold Hunt optimization – pass five
Parallelization with the multiprocessing module
Introduction to parallelization
Shared memory parallelization
Distributed memory parallelization
Global interpreter lock
The multiprocessing module
The Pool class
Parallelizing the Gold Hunt program
Revisiting the gold field
Gold Hunt optimization – Pass six, parallelization
Other methods for parallelization
Further reading
JIT compilers
GPU accelerated computing
Summary
10. Simple GUI Applications
Overview of GUI frameworks
Tkinter
PyQt
PySide
Kivy
wxPython
GUI programming design considerations
Understanding user requirements
Developing a user story
Simplicity and accessibility
Consistency
Predictability and familiarity
Miscellaneous design considerations
Event-driven programming
Event
Event handling
Event loop
GUI programming with Tkinter
Tkinter documentation links
The mainloop() in Tkinter
Simple GUI application – Take 1
Simple GUI application – Take 2
GUI Widgets in Tkinter
Geometry management
Grid geometry manager
Pack geometry manager
Place geometry manager
Events in Tkinter
Event types
Event descriptors
Event object attributes
Event handling in Tkinter
Command callback (Button widget)
The bind() method
The bind_class() method
The bind_all() method
Project-1 – Attack of the Orcs V10.0.0
Background scenario
Problem statement
Writing the code
Overview of the class HutGame
The __init__ method
The occupy_huts method
The create_widgets method
The setup_layout method
The radio_btn_pressed and enter_hut methods
The announce_winner method
Running the application
MVC architecture
Model
View
Controller
Advantages of MVC
Project 2 – Attack of the Orcs v10.1.0
Revisiting the HutGame class
Creating MVC classes
Communication between MVC objects
Controller to Model or View communication
Model to Controller communication
Using method assignment
Using a publish-subscribe pattern
PyPubSub package
View to Controller communication
Communication between View and Model
Reviewing the code
The Controller class
The Model class
The View class
Running the application
Testing GUI applications
Testing considerations
Unit testing and MVC
Manual testing
Automated GUI testing
Exercises
Further reading
Summary
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜