Skip to: site menu | section menu | main content

IronPython in Action

Unleashing .NET with Python
Currently viewing: Front Page » Download Sources » About

About this Book & Table of Contents

Quotes on IronPython in Action

About IronPython in Action

IronPython is a radical project for Microsoft. It is the first project to be released under their Ms-PL (Microsoft Public License) open source license. It is also a radically different language from the ones that Microsoft has traditionally promoted for the .NET framework. IronPython is an implementation of the popular programming language Python for .NET. Python is an open source, object-oriented, dynamically typed language in use by organizations like Google, NASA and Pixar. Python is a multi-paradigm language, and brings new possibilities to .NET programmers: not just the added flexibility of dynamic typing, but programming styles such as functional programming and metaprogramming. For Python programmers the powerful runtime, with its JIT compiler and huge range of .NET libraries, also presents new opportunities.

The goal of IronPython in Action is not just to teach the mechanics of using IronPython, but to demonstrate the power and effectiveness of object-oriented programming in the Python language. To this end we cover best practices in API design, testing, and the use of design patterns in structured application development. In part this is to dispel the myth that dynamic languages are merely scripting languages; but mostly it is to help you make the best of the language and the platform on which it runs.

The addition of Python to the range of languages available as first-class citizens in .NET reflects the changes happening in the wider world of programming. No one says it better than Anders Hejlsberg, the architect of C#, when asked by Computer World what advice he had for up-and-coming programmers:

Go look at dynamic languages and meta-programming: those are really interesting concepts. Once you get an understanding of these different kinds of programming and the philosophies that underlie them, you can get a much more coherent picture of what’s going on and the different styles of programming that might be more appropriate for you with what you’re doing right now.

Anyone programming today should check out functional programming and meta-programming as they are very important trends going forward.

Who should read this book?

IronPython in Action is particularly aimed at two types of programmers: Python programmers looking to take advantage of the power of the .NET framework or Mono for their applications, and .NET programmers interested in the flexibility of dynamic languages. It assumes no experience of either Python or .NET, but does assume some previous programming experience. If you have some programming experience, but have never used either of these systems, you should find IronPython in Action an accessible introduction to both Python and .NET.

Just as Python is suited to an enormous range of problem domains, so is IronPython. The book covers a range of different uses of IronPython: from web development to application development, one-off scripting to system administration, and embedding into .NET applications for extensible architectures or providing user scripting.

IronPython in Action is available from:

You can use the code ironpython35 for a 35% discount off IronPython in Action from Manning (both ebook and print book).

You can get the sourcecode that accompanies the book from the Download Page.

Table of Contents

Part 1: Getting Started with IronPython

  1. A New Language for .NET

    1.1 An Introduction to IronPython

    1.1.1 What is IronPython?
    1.1.2 A Brief History of IronPython
    1.1.3 IronPython for Python Programmers
    1.1.4 IronPython for .NET Programmers

    1.2 Python on the CLR

    1.2.1 Dynamic Languages on .NET and the DLR
    1.2.2 Silverlight, a New CLR
    1.2.3 The Python Programming Language
    1.2.4 Multiple Programming Paradigms

    1.3 Live Objects on the Console - the Interactive Interpreter

    1.3.1 Using the Interactive Interpreter
    1.3.2 .NET Framework: assemblies, namespaces and classes
    1.3.3 Live objects and the Interactive Interpreter
    1.3.4 Object Introspection with dir and help

    1.4 Summary

  2. Introduction to Python

    2.1 An Overview of Python

    2.1.1 Python datatypes
    2.1.2 Names, Objects and References
    2.1.3 Mutable and immutable objects

    2.2 Python: Basic Constructs

    2.2.1 Statements and expressions
    2.2.2 Conditionals and loops
    2.2.3 Functions
    2.2.4 Built in Functions
    2.2.5 Classes

    2.3 Additional Python Features

    2.3.1 Exception Handling
    2.3.2 Closures and scoping rules
    2.3.3 List Comprehensions
    2.3.4 Modules, Packages and Importing
    2.3.5 Docstrings
    2.3.6 The Python Standard Library

    2.4 Summary

  3. .NET Objects & IronPython

    3.1 Introducing .NET

    3.1.1 Translating MSDN Documentation into IronPython
    3.1.2 The Form Class

    3.2 Structures, Enumerations and Collections: .NET Types

    3.2.1 Methods and properties inherited from Control
    3.2.2 Adding a Label to the Form: ControlCollection
    3.2.3 Configuring the Label: The Color Structure
    3.2.4 The FormBorderStyle Enumeration
    3.2.5 Hello World with Form and Label

    3.3 Handling Events

    3.3.1 The MouseMove Event
    3.3.2 Event Handlers in IronPython

    3.4 Subclassing .NET Types

    3.5 Summary

Part 2: Core Development Techniques

  1. Writing an Application, and Design Patterns with IronPython

    4.1 Data Modelling and Duck Typing

    4.1.1 Python and Protocols
    4.1.2 Duck Typing in Action

    4.2 Model View Controller in IronPython

    4.2.1 Introducing the Running Example
    4.2.2 The View Layer: Creating a User Interface
    4.2.3 A Data Model
    4.2.4 A Controller Class

    4.3 The Command Pattern

    4.3.1 The SaveFileDialog
    4.3.2 Writing Files: the .NET & Python Ways
    4.3.3 Handling exceptions and the system message box
    4.3.4 The Save Command, a Python Class
    4.3.5 The SaveAs Command

    4.4 Integrating Commands with Our Running Example

    4.4.1 Menu Classes and Lambda
    4.4.2 Toolbar and Images, .NET Classes
    4.4.3 Bringing the GUI to Life

    4.5 Summary

  2. First Class Functions in Action with XML

    5.1 First Class Functions

    5.1.1 Higher Order Functions
    5.1.2 Python Decorators
    5.1.3 A Null Argument Checking Decorator

    5.2 Representing Documents with XML

    5.2.1 The .NET XmlWriter
    5.2.2 A DocumentWriter Class
    5.2.3 An Alternative with an Inner Function

    5.3 Reading XML

    5.3.1 XmlReader
    5.3.2 An IronPython XML Document Reader

    5.4 Handler Functions for MultiDoc XML

    5.5 The Open Command

    5.6 Summary

  3. Properties, Dialogs and Visual Studio

    6.1 Document Observers

    6.1.1 Python properties
    6.1.2 Document Observers on the MainForm
    6.1.3 Adding the OpenCommand

    6.2 More with TabPages: Dialogs and Visual Studio

    6.2.1 Remove Pages: Ok and Cancel Dialog
    6.2.2 Rename Pages: A Modal Dialog
    6.2.3 Visual Studio Express and IronPython
    6.2.4 Adding Pages: Code Reuse in Action
    6.2.5 Wiring the Commands to the View

    6.3 Object Serializing with BinaryFormatter

    6.4 Summary

  4. Agile Testing - Where Dynamic Typing Shines

    7.1 The unitest module

    7.1.1 Creating a TestCase
    7.1.2 setup and tearDown
    7.1.3 Test Suites with Multiple Modules

    7.2.Testing with Mocks

    7.2.1 Mock Objects
    7.2.2 Modifying Live Objects: The Art of the Monkey Patch
    7.2.3 Mocks and Dependency Injection

    7.3 Functional Testing

    7.3.1 Interacting with the GUI Thread
    7.3.2 An AsyncExecutor for Asynchronous Interactions
    7.3.3 The Functional Test: Making MultiDoc Dance

    7.4 Summary

  5. Getting Deeper into IronPython: Metaprogramming, Protocols and More

    8.1 Protocols instead of Interfaces

    8.1.1 A Myriad of Magic Methods
    8.1.2 Operator Overloading
    8.1.3 Iteration
    8.1.4 Generators
    8.1.5 Equality and Inequality

    8.2 Dynamic Attribute Access

    8.2.1 Attribute Access through Builtin Functions
    8.2.2 Attribute Access through Magic Methods
    8.2.3 Proxying Attribute Access

    8.3 Metaprogramming

    8.3.1 Introduction to Metaclasses
    8.3.2 Uses of Metaclasses
    8.3.3 A Profiling Metaclass

    8.4 IronPython and the CLR

    8.4.1 .NET Arrays
    8.4.2 Overloaded Methods
    8.4.3 'out', 'ref', 'params' and Pointer Parameters
    8.4.4 Value Types
    8.4.5 Interfaces
    8.4.6 Attributes


Part 3: IronPython and Advanced .NET

  1. WPF and IronPython

    9.1 Hello World with WPF and IronPython

    9.1.1 WPF from Code
    9.1.2 Hello World from XAML

    9.2 WPF in Action

    9.2.1 Layout with the Grid
    9.2.2 The WPF ComboBox and CheckBox
    9.2.3 The Image Control
    9.2.4 The Expander
    9.2.5 The ScrollViewer
    9.2.6 The TextBlock a Lightweight Document Viewer
    9.2.7 The XamlWriter

    9.3 XPS Documents and Flow Content

    9.3.1 FlowDocument Viewer Classes
    9.3.2 Flow Document Markup
    9.3.3 Document XAML and Object Tree Processing

    9.4 Summary

  2. Windows System Administration with IronPython

    10.1 System Administration with IronPython

    10.1.1 Simple Scripts
    10.1.2 Shell Scripting with IronPython

    10.2. WMI and the System.Management Assembly

    10.2.1 System.Management
    10.2.2 Connecting to remote Computers

    10.3 Powershell & IronPython

    10.3.1. Using Powershell from IronPython
    10.3.2. Using IronPython inside Powershell

    10.4 Summary

  3. IronPython and ASP.NET

    11.1 Introducing ASP.NET

    11.1.1 Web controls
    11.1.2 Pages and user controls
    11.1.3 Rendering, server code and the page lifecycle

    11.2 Adding IronPython to ASP.NET

    11.2.1 Writing a first application
    11.2.2 Creating a project

    11.3 ASP.NET Infrastructure

    11.3.1 The App_Script Folder
    11.3.2 The File
    11.3.3 The Web.config File

    11.4 A Web-based MultiDoc Viewer

    11.4.1 Page Structure
    11.4.2 Code-behind

    11.5 Editing MultiDocs

    11.5.1 Swapping Controls
    11.5.2 Handling Viewstate
    11.5.3 Additional Events

    11.6 Converting the Editor into a User Control

    11.6.1 Viewstate Again
    11.6.2 Adding Parameters

    11.7 Summary

  4. Databases and Web Services

    12.1 Relational databases and ADO.NET

    12.1.1 Trying it out using PostgreSQL
    12.1.2 Connecting to the database
    12.1.3 Executing commands
    12.1.4 Setting parameters
    12.1.5 Querying the database
    12.1.6 Reading multi-row results
    12.1.7 Using transactions
    12.1.8 DataSets
    12.1.9 Databinding

    12.2 Web services

    12.2.1 Using a simple web service
    12.2.2 Using SOAP services from IronPython
    12.2.3 REST services in IronPython

    12.3 Summary

  5. Silverlight: IronPython in the Browser

13.1. Introduction to Silverlight

13.1.1. Dynamic Silverlight
13.1.2. Your Python Application
13.1.3. Silverlight Controls
13.1.4. Packaging a Silverlight Application

13.2. A Silverlight Twitter Client

13.2.1. Cross Domain Policies
13.2.2. Debugging Silverlight Applications
13.2.3. The User Interface and a Password TextBox
13.2.4. Accessing Network Resources
13.2.5. Threading and Dispatching onto the UI Thread
13.2.6. IsolatedStorage in the Browser

13.3. Videos and the Browser DOM

13.3.1. The MediaElement Video Player
13.3.2. Interacting with the Browser DOM

13.4. Summary

Part 4: Reaching Out with IronPython

  1. Extending IronPython with C# / VB.NET

14.1. Writing a Class Library for IronPython

14.1.1. Working with Visual Studio or MonoDevelop
14.1.2. Python Objects from Class Libraries
14.1.3. Calling Unmanaged Code with the P/Invoke Attribute
14.1.4. Methods with Attributes through Subclassing

14.2. Creating Dynamic (and Pythonic) Objects from C# / VB.NET

14.2.1. Creating Dynamic Objects
14.2.2. Python Magic Methods
14.2.3. APIs with Keyword and Multiple Arguments

14.3. Compiling and Using Assemblies at Runtime

14.4. Summary

  1. Embedding the IronPython Engine

15.1. Creating a custom Executable

15.1.1. The IronPython Engine
15.1.2. Executing a Python File

15.2. IronPython as a Scripting Engine

15.2.1. Setting and Fetching Variables from a Scope
15.2.2. Providing Modules and Assemblies for the Engine
15.2.3. Python Code as an Embedded Resource

15.3. Python Plugins for .NET Applications

15.3.1. A Plugin Class and Registry
15.3.2. Auto-discovery of User Plugins
15.3.3. Calling the User Plugins

15.4. Using DLR Objects from Other .NET Languages

15.4.1. Expressions, Functions and Python Types
15.4.2. Dynamic Operations with ObjectOperations
15.4.3. The Builtin Python Functions and Modules

15.5. Summary

Back to top