Instructor-led training
Python II: Applied Python Training in Key West, Florida
This 4 day course picks up where Python I leaves off, covering some topics in more detail, and adding many new ones, with a focus on enterprise development.
What you'll learn
Private Training for Teams
This course is offered as private, instructor-led training for organizations, onsite in Key West, Florida or live online. Dates, delivery format, and course content are arranged around your team's requirements.
This course is not currently scheduled as a public class for individual enrollment.
Request Group TrainingPrerequisites
Course Outline
1. Python Refresher
Variables
Python Data Types
Sequences
Mapping Types
Program Structure
Files an Console I/O
Conditionals
Loops
Defining a Function
Function Parameters
Builtins
2. OS Services
The os Module
Environment Variables
Launching external programs
Paths, Directories and Filenames
Walking Directory Trees
Dates and Times
The Time Module
The Calendar Module
3. Pythonic Programming
Common Python Idioms
Slicing and Dicing
Unpacking Function Arguments
Lambda Functions
Nested Functions
List Comprehensions
Iterables
Generator Expressions
Writing Generators
Python Time Travel
Three Python Easter Eggs
A String Trick
String Formatting
4. Modules and Packages
Modules
Using import
Initialization Code
Namespaces
Executing Modules as Scripts
Packages
Configuring Import with
__init__.py
Name Resolution (AKA scope)
Nested Functions
Python Style
5. Classes
About OO Programming
Defining Classes
Constructors
Instance Methods
Properties
Class Methods and Data
Static Methods
"Private" Methods
Inheritance
Untangling the Nomenclature
6. Metaprogramming
Special Attributes
globals() and locals()
Working with Attributes
The inspect module
Decorators
Decorator Functions
Decorator Classes
Decorating Classes
Creating Classes at Runtime
Monkey Patching
7. Objectives
Program Development
Comments
Pylint
Customizing pylint
Using pyreverse
The unittest module
Skipping Tests
Making a suite of tests
Automated test discovery
Using Nose
The Python Debugger
Starting debug mode
Stepping through a Program
Setting Breakpoints
Profiling
Benchmarking
8. Distributing Modules
Installing Packages
Ways to distribute code
Overview of distutils
Preparing for distribution
Creating a source distribution
Creating built distributions
Setup.py Options
Setup.py Commands
Code Portability
9. Database Access
The DB API
Available Interfaces
Connecting to a Server
Creating a Cursor
Executing a Statement
Fetching Data
Tip: Making an iterator for large queries
Parameterized Statements
Dictionary Cursors
Metadata
Transactions
Object-relational Mappers
10.qt GUI Programming with PyQt4
What is PyQt4?
Event Driven Applications
GUI Application Flow Chart
External Anatomy of a PyQt4
Application
Internal Anatomy of a PyQt4
Application
Using designer
Anatomy of a designer-based application
Naming Conventions
Common Widgets
Layouts
Selectable Buttons
Making your application stretch
Actions and Events
Menu Bar
Status Bar
Using predefined dialogs
Creating Custom Dialogs
Tabs
Niceties
Working with Images
10.tk GUI Programming with Tkinter
Objectives
Tkinter Overview
Basic Tkinter Programming
Object-oriented Tkinter
Widgets
Labels
Buttons
Setting Fonts
Colors
Standard Colors
Variable Wrappers
Selectable Buttons
Text Entry Blanks
Multiline Text Entry/Display
Listbox
Arranging Widgets
Using pack()
Tweaking the layout
Frames
Adding Scrollbars
Callbacks
Callback Parameters
Binding Events
Event Specifications
Creating Menus
11. Network Programming
Sockets
Socket options
Client Concepts
Server Concepts
Application Protocols
Forking Servers
Grabbing HTML from the Web
Consuming Web Services
Web Data the Easier Way
Sending email
Binary Data
The struct module
12. Multiprogramming
What are Threads?
The Python Thread Manager
The threading module
Threads for the impatient
Creating a thread class
Variable Sharing
Using Queues
Debugging threaded programs
The multiprocessing module
Alternatives to multiprogramming
13. System Administration
The subprocess module
subprocess convenience functions
Using the sh module
Remote access
Other useful modules
Permissions
Saving Information
Creating a useful command line script
Creating Filters
Parsing the command line
Simple logging
Logging Levels
Formatting Log Entries
Logging to other Destinations
14. XML and JSON
About XML
Normal approaches to XML
Which module to use?
Getting Started with ElementTree
How ElementTree works
Creating a new XML Document
Parsing an XML Document
Navigating the XML Document
Using XPath
About JSON
Reading JSON
Writing JSON
15. Extending Python
Why extend Python?
Ways to extend Python with C
Hand-coded C
Overview
The C Program
Methods
The Method Table
The init function
Handling errors
Custom exception objects
Putting it all together
Using SWIG
The interface file
Generating the Wrappers
Building and installing the extension
cytpes
Appendix A: Books
Appendix B: String Formatting
What makes this material hard to master
Most of this course is not new syntax. It is a set of different ways to structure Python programs, plus a survey of the libraries used in enterprise and administrative work. The syllabus layers the topics in a deliberate order.
- Idioms before abstractions. The Pythonic Programming block covers list comprehensions, iterables, generator expressions, writing generators, lambda functions and unpacking function arguments. Developers who translate loops from another language often get correct but unidiomatic code. Generators are the first place where lazy evaluation changes how a program behaves.
- Scope and namespaces. Modules and Packages covers import, initialization code, namespaces,
__init__.pyand name resolution (scope). Misunderstood scope rules cause many hard-to-trace bugs, and nested functions and decorators later in the course depend on them. - Classes, then metaprogramming. After properties, class and static methods, "private" methods and inheritance, the course moves to special attributes,
globals()andlocals(), theinspectmodule, decorator functions and classes, decorating classes, creating classes at runtime and monkey patching. The common misconception is that these are only clever tricks. They are powerful but easy to overuse, and they make code harder to debug. - Concurrency. The Multiprogramming block covers the
threadingmodule, variable sharing, queues, debugging threaded programs andmultiprocessing. Shared state is where intermittent bugs come from, so the course also covers alternatives to multiprogramming. - Crossing the language boundary. Extending Python covers hand-coded C extensions (the method table, the init function, error handling, custom exception objects), SWIG and ctypes. This is the one area that needs some C knowledge.
Several blocks are applied surveys: database access, network programming, XML and JSON, system administration, and two GUI toolkits (PyQt4 and Tkinter). Their difficulty is in choosing and combining modules rather than in any single concept.
Who it suits and where to go next
The course targets advanced users, system administrators, web site administrators and anyone who wants to automate common tasks with Python. Students should already be able to write simple scripts using basic data types, program structures and the standard library. The refresher chapter reviews these quickly but does not teach them from scratch. If you need to build those skills first, Beginning Python is a place to start.
Once you are comfortable with decorators, packaging, testing and the other topics here, Advanced Python 3 (4 Day Course) is a natural next step for going deeper into the language. The Python Programming learning guide lists the other courses by level.
The syllabus names specific tool versions, such as PyQt4 and nose. Organizations that work with different library or interpreter versions can ask about a customized private training proposal.
Illustrative scenarios
The scenarios below are illustrations of how the course material can be applied. They are not descriptions of specific organizations or of the course's lab exercises.
- Server maintenance automation. An operations team might combine walking directory trees, the
subprocessmodule, permissions, command-line parsing and the logging module (levels, formatting, other destinations). The result is a script that audits files and runs external tools, with log output that can go somewhere other than the console. - Reporting from a database. A team might use the DB API with parameterized statements, dictionary cursors and transactions. For a large query, it could use the course's tip on wrapping fetches in an iterator to keep memory use low, then write the results out with the JSON writing topics.
- Integrating with partner systems. A developer might parse an XML feed with ElementTree and XPath, consume a web service, and send a summary by email. Worker threads fed by a queue could handle several feeds at once, and a decorator could add logging or retry behavior without touching each function.
AI coding assistants and these topics
AI coding assistants are useful for first drafts of routine code: directory-walking scripts, argument parsing, ElementTree navigation, boilerplate for DB API calls, and unittest test cases. They are also good at explaining a comprehension or decorator you did not write.
They fail in predictable places for this syllabus:
- Shared state in threads. Generated threaded code can look right and still have races around shared variables. Queues are usually the safer pattern, and you have to check that the assistant used them.
- Database and shell calls. Assistants sometimes build SQL or command strings by concatenation. Check that queries use parameterized statements and that
subprocesscalls do not pass untrusted input through a shell. - Metaprogramming. Decorators, runtime class creation and monkey patching often work on the happy path but change function metadata or behavior elsewhere. Examine the result with
inspect. - Version and library mismatch. Suggested code may use APIs from a different Python version or GUI toolkit than your environment. This matters for PyQt4 and Tkinter code in particular.
- C extensions. Treat generated extension code or SWIG interface files as untrusted until you have built and exercised them, including their error paths.
To verify, run the code and write unittest cases for empty input, bad paths and encoding or binary-data edge cases. Run pylint, step through suspicious code in the Python debugger, and profile before accepting performance claims.
Frequently asked questions
What level is Python II: Applied Python?
It is a general-level, four-day, hands-on course that follows an introductory Python course. It suits system administrators, web site administrators, and developers who want to automate tasks or build enterprise tools in Python.
What should I know before attending?
You should be able to write simple Python scripts using basic data types, program structures and the standard library. The first chapter is a refresher, but it moves quickly.
What does the syllabus cover?
It covers OS services, Pythonic idioms (comprehensions, generators), modules and packages, classes, metaprogramming (decorators, runtime class creation), testing, debugging and profiling, distributing modules, database access, GUI programming with PyQt4 and Tkinter, network programming, threads and multiprocessing, system administration scripting, XML and JSON, and extending Python with C.
Can this course be delivered privately, onsite or online?
Yes. HSG delivers private training for organizations either onsite at the client's location or live online.
Can the content be customized?
Private courses can be tailored, including to the technology versions your organization uses. Use the training proposal request to describe your environment and goals.
Training locations
Python II: Applied Python training across the U.S. and beyond.
We provide private Python II: Applied Python training for organizations, onsite at your location or live online, throughout the United States and internationally.
View all Python II: Applied Python training locations
Train your team with HSG
Private, instructor-led training customized for your organization.
- Onsite or live online delivery
- Customized curriculum
- For a single employee or an entire team
- Flexible scheduling
- Experienced instructors
Questions? Call us at 303.377.6176
or email info@hartmannsoftware.com
Ready to train your team?
Let's customize this training for your organization.
Tell us about your employees, your goals, and your preferred schedule. We'll prepare a training proposal covering scope, delivery format, and pricing.