/Languages/IronPython/Public/Tutorial/Tutorial.htm
HTML | 2821 lines | 2795 code | 26 blank | 0 comment | 0 complexity | f3649312a6d6a8ae14c1d3d28296cd5b MD5 | raw file
Possible License(s): CPL-1.0, BSD-3-Clause, ISC, GPL-2.0, MPL-2.0-no-copyleft-exception
Large files files are truncated, but you can click here to view the full file
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
- <title>IronPython Tutorial</title>
- <link rel="stylesheet" type="text/css" href="../Doc/IronPython.css" />
- <style type="text/css">
- p.AntiVerify { display : none; }
- p.Code-Background { color : gray; }
- p.NoVerify-Background { color : gray; }
- p.Code-Highlighted { color : gray; }
- p.NoVerify-Highlighted { color : gray; }
- p.CodeSample { color:blue; }
- p.DOSCommand { color:green; }
- p.ExceptionExample { color:green; }
- p.ExceptionOutput {display : none; }
- p.HiddenCode { display : none; }
- p.HiddenOutput {display : none; }
- p.LooseVerify { display : none; }
- p.Stepnonumbering { text-indent: 2em; }
- p.TypedExample { color : green; }
- p.UserExample { color : green; }
- p.UserCode { color:green; }
- </style>
- </head>
- <body lang="EN-US">
- <div class="Section1">
- <p class="Title1">IronPython Tutorial</p>
- <p class="Title2">A tour of Python on .NET</p>
- <p class="Title2"> </p>
- <hr />
- <p class="CopyrightText">Information in this document is subject to change without
- notice. The example companies, organizations, products, people, and events depicted
- herein are fictitious. No association with any real company, organization, product,
- person or event is intended or should be inferred. Complying with all applicable
- copyright laws is the responsibility of the user. Without limiting the rights
- under copyright, no part of this document may be reproduced, stored in or introduced
- into a retrieval system, or transmitted in any form or by any means (electronic,
- mechanical, photocopying, recording, or otherwise), or for any purpose, without
- the express written permission of Microsoft Corporation.</p>
- <p class="CopyrightText"> </p>
- <p class="CopyrightText">Microsoft may have patents, patent applications, trademarked,
- copyrights, or other intellectual property rights covering subject matter in
- this document. Except as expressly provided in any written license agreement
- from Microsoft, the furnishing of this document does not give you any license
- to these patents, trademarks, copyrights, or other intellectual property.</p>
- <p class="CopyrightText"> </p>
- <p class="CopyrightText">© Microsoft Corporation. All rights reserved.</p>
- <p class="CopyrightText"> </p>
- <p class="CopyrightText">Microsoft, MS-DOS, MS, Windows, Windows NT, MSDN, Active
- Directory, BizTalk, SQL Server, SharePoint, Outlook, PowerPoint, FrontPage,
- Visual Basic, Visual C++, Visual J++, Visual InterDev, Visual SourceSafe, Visual
- C#, Visual J#, and Visual Studio are either registered trademarks or trademarks
- of Microsoft Corporation in the U.S.A. and/or other countries.</p>
- <p class="CopyrightText"> </p>
- <p class="CopyrightText">Other product and company names herein may be the trademarks of their respective owners.</p>
- <hr />
- <p class="ContentsHeading">Contents</p>
- <p class="Toc1"><a href="#Intro">Introduction</a></p>
- <p class="Toc1">Tutorial 1: <a href="#T1">Basic IronPython</a></p>
- <p class="Toc2">Exercise 1: <a href="#T1.1">The IronPython interactive console</a></p>
- <p class="Toc3">Task 1: <a href="#T1.1.1">IronPython console</a></p>
- <p class="Toc3">Task 2: <a href="#T1.1.2">Built-in modules and interactive exploration</a></p>
- <p class="Toc3">Task 3: <a href="#T1.1.3">External Python modules</a></p>
- <p class="Toc2">Exercise 2: <a href="#T1.2">Using the standard .NET libraries from IronPython</a></p>
- <p class="Toc3">Task 1: <a href="#T1.2.1">Basic .NET library use</a></p>
- <p class="Toc3">Task 2: <a href="#T1.2.2">Working with .NET classes</a></p>
- <p class="Toc3">Task 3: <a href="#T1.2.3">Generics</a></p>
- <p class="Toc2">Exercise 3: <a href="#T1.3">Loading additional .NET libraries</a></p>
- <p class="Toc3">Task 1: <a href="#T1.3.1">Using System.Xml - AddReference</a></p>
- <p class="Toc3">Task 2: <a href="#T1.3.2">Mapack - Loading the .NET libraries - AddReferenceToFile</a></p>
- <p class="Toc2">Exercise 4: <a href="#T1.4">Obtaining and Using the Python Standard Library</a></p>
- <p class="Toc3">Task 1: <a href="#T1.4.1">Configuring IronPython to use the Python standard library</a></p>
- <p class="Toc1">Tutorial 2: <a href="#T2">Advanced IronPython</a></p>
- <p class="Toc2">Exercise 1: <a href="#T2.1">Events and Delegates</a></p>
- <p class="Toc3">Task 1: <a href="#T2.1.1">File System Watcher</a></p>
- <p class="Toc3">Task 2: <a href="#T2.1.2">Improving the event handler</a></p>
- <p class="Toc3">Task 3: <a href="#T2.1.3">Defining events in Python</a></p>
- <p class="Toc2">Exercise 2: <a href="#T2.2">Windows Forms</a></p>
- <p class="Toc3">Task 1: <a href="#T2.2.1">Simple Windows Forms application</a></p>
- <p class="Toc2">Exercise 3: <a href="#T2.3">Windows Presentation Foundation (Avalon)</a></p>
- <p class="Toc3">Task 1: <a href="#T2.3.1">Simple Avalon Application</a></p>
- <p class="Toc3">Task 2: <a href="#T2.3.2">Avalon calculator</a></p>
- <p class="Toc1">Tutorial 3: <a href="#T3">IronPython and COM interoperability</a></p>
- <p class="Toc2">Exercise 1: <a href="#T3.1">Use Word for Spell Checking</a></p>
- <p class="Toc3">Task 1: <a href="#T3.1.1">Accessing Word and Checking
- Spelling</a></p>
- <p class="Toc3">Task 2: <a href="#T3.1.2">Use Windows Form Dialog to Correct
- Spelling</a></p>
- <p class="Toc1">Tutorial 4: <a href="#T4">Debugging IronPython programs</a></p>
- <p class="Toc2">Exercise 1: <a href="#T4.1">Debugging IronPython programs</a></p>
- <p class="Toc3">Task 1: <a href="#T4.1.1">Debugging IronPython programs using Microsoft CLR Debugger</a></p>
- <p class="Toc1">Tutorial 5: <a href="#T5">Extending IronPython</a></p>
- <p class="Toc2">Exercise 1: <a href="#T5.1">Extending using C#</a></p>
- <p class="Toc3">Task 1: <a href="#T5.1.1">Implementing a simple class - constructor and ToString</a></p>
- <p class="Toc3">Task 2: <a href="#T5.1.2">Making the object enumerable</a></p>
- <p class="Toc3">Task 3: <a href="#T5.1.3">Adding a custom operator</a></p>
- <p class="Toc3">Task 4: <a href="#T5.1.4">Adding a delegate</a></p>
- <p class="Toc2">Exercise 2: <a href="#T5.2">Extending using Visual Basic.NET</a></p>
- <p class="Toc3">Task 1: <a href="#T5.2.1">Implementing a simple class - constructor and ToString</a></p>
- <p class="Toc3">Task 2: <a href="#T5.2.2">Making the object enumerable</a></p>
- <p class="Toc3">Task 3: <a href="#T5.2.3">Adding a custom operator</a></p>
- <p class="Toc3">Task 4: <a href="#T5.2.4">Adding a delegate</a></p>
- <p class="Toc1">Tutorial 6: <a href="#T7">Using Visual Studio to Edit .py
- Files and Debug Them</a></p>
- <p class="Toc2">Exercise 1: <a href="#T6.1">Setting up Visual Studio for
- IronPython Debugging</a></p>
- <p class="Toc3">Task 1: <a href="#T6.1.1">Setting up Visual Studio for
- IronPython Debugging</a></p>
- </div>
- <div class="Section2">
- <h1><a name="Intro">Introduction</a></h1>
- <p class="Normal">IronPython is the .NET implementation of the Python programming language
- (<a href="http://www.python.org">www.python.org</a>). It's a dynamically typed language with support
- for many programming paradigms such as imperative, object-oriented, and functional programming, and also allows
- you to seamlessly use existing .NET code.</p>
- <p class="Normal"> </p>
- <p class="Normal">The goal of this tutorial is to quickly familiarize you with the
- IronPython console and to show you how to make use of the extensive .NET libraries
- available. This tutorial also shows you how to get started in more specialized
- areas such as interoperating with <a href="http://www.microsoft.com/com/default.mspx">COM</a>
- and extending IronPython with C# and/or Visual Basic. While we do explain some
- finer points of Python's syntax, this tutorial is NOT meant to be an introduction to
- Python itself, and if you're looking for that, we recommend you start with the tutorial at
- <a href="http://docs.python.org/tut/tut.html">www.python.org</a>
- or the often recommended book
- <a href="http://oreilly.com/catalog/9780596513986/"><i>Learning Python</i></a>
- by Mark Lutz and David Ascher. In addition,
- <a href="http://www.ironpythoninaction.com/"><i>IronPython in Action</i></a>
- by Michael Foord and Christian Muirhead is a definitive guide that includes
- a wealth of IronPython-specific information.<br><br>
- Some of the exercises in this tutorial require specific software installations.
- The prerequisites to successfully complete the whole tutorial are:</p>
- <ul type="disc">
- <li class="Normal">Microsoft .NET Framework Version 4.0
- <ul type="circle">
- <li class="Normal">Required to run IronPython.</li>
- <li class="Normal">Download from
- <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=9cfb2d51-5ff4-4491-b0e5-b386f32c0992&displaylang=en">here</a>.</li>
- </ul>
- </li>
- </ul>
- <ul>
- <li class="Normal">Visual Studio 2010
- <ul type="circle">
- <li class="Normal">Very useful for the C#/VB extending tutorials.</li>
- <li class="Normal">Separate .NET 4.0 installation is not required if
- Visual Studio 2010 is installed.</li>
- <li class="Normal">Download from
- <a href="http://www.microsoft.com/visualstudio">here</a>.</li>
- </ul>
- </li>
- <li class="Normal"><a name="Mapack">Mapack</a> (example assembly found
- on the internet)<ul>
- <li>Required for the turorial "<a href="#T1">Basic IronPython</a>"
- and exercise "<a href="#T1.3">Loading additional .NET Libraries</a>".</li>
- <li>Download Mapack from
- <a href="http://www.lutzroeder.com/dotnet/">here</a> (direct link
- to the Mapack.zip download is
- <a href="http://www.lutzroeder.com/dotnet/Download.aspx?File=Mapack">here</a>).</li>
- <li>Extract Mapack.dll from the zip file directly into the Tutorial
- directory.</li>
- </ul>
- </li>
- </ul>
- <p class="Normal"> </p>
- <p class="Body">This tutorial assumes that the IronPython distribution was uncompressed
- into the directory C:\IronPython. Please note that your individual setup may
- vary.</p>
- <p class="Body">This tutorial also assumes that you will launch the
- IronPython console (c:\ironpython\ipy.exe) from the tutorial directory.
- When the tutorials direct you to start the IronPython console from the tutorial directory,
- you should change to the tutorial directory (>cd c:\ironpython\tutorial)
- and launch the console with the tutorial as your working directory (>..\ipy.exe).</p>
- <a name="VS2005Note"></a>
- <p class="Body"> </p>
- <h1><a name="T1">Tutorial 1: Basic IronPython</a></h1>
- <p class="Body">The emphasis of this tutorial is on the basic interaction with
- the IronPython interpreter and using the interactive environment to explore
- the .NET libraries.</p>
- <p class="Body">Estimated time to complete this tutorial: <b>30 minutes</b></p>
- <p class="Body">The objective of this tutorial is to launch the IronPython interpreter,
- explore the environment of the interactive console and use IronPython to interact
- with .NET libraries.</p>
- <p class="Body">The exercises in this tutorial are:</p>
- <ul>
- <li>
- <p class="ExerciseList"><a href="#T1.1">The IronPython interactive console</a></p>
- </li>
- <li>
- <p class="ExerciseList"><a href="#T1.2">Using the standard .NET libraries
- from IronPython</a></p>
- </li>
- <li>
- <p class="ExerciseList"><a href="#T1.3">Loading additional .NET libraries</a></p>
- </li>
- </ul>
- <h2><a name="T1.1">Exercise 1: The IronPython interactive console</a></h2>
- <p class="Body">In this exercise, you will start the IronPython interactive
- interpreter and perform simple tasks to become acquainted with the IronPython
- environment.</p>
- <p class="Normal">If you are familiar with using the Python interactive console,
- the import statement and exploring the Python interactive environment using
- dir() function and __doc__ attribute, you can <a href="#T1.2">skip this exercise</a>.</p>
- <h3><a name="T1.1.1">Task 1: IronPython console</a></h3>
- <ol>
- <li>
- <p class="Step">Start the IronPython console from the tutorial directory
- by changing to the tutorial directory (>cd c:\ironpython\tutorial) and
- launching the console c:\ironpython\ipy.exe executable (>..\ipy.exe).
- This is how you should always launch the console for the tutorials, but
- from now on, we'll just direct you to "start the IronPython console from
- the tutorial directory".</p>
- </li>
- </ol>
- <p class="Code-Highlighted">IronPython 2.7 (2.7.10920.0) on .NET 4.0.30319.1<br />
- Type "help", "copyright", "credits" or "license" for more information.</p>
- <p class="Code-Highlighted">>>> _</p>
- <ol start="2">
- <li>
- <p class="Step">IronPython's console interfaces with the user in a standard
- Read-Eval-Print Loop, or REPL. This means that the console repeatedly reads
- user input, evaluates the statement, prints the result (if any), and awaits
- more input. Try it out by executing the simple statements listed below.
- <b>Note:</b> The input line starting with 'for' requires an extra press of
- the enter key afterwards as a signal to the interpreter that there are no
- more statements in the 'for' loop.</p>
- </li>
- </ol>
- <p class="TypedExample">2+2</p>
- <p class="TypedExample">print "Hello World!"</p>
- <p class="TypedExample">for i in range(3): print i</p>
- <p class="TypedExample">x = 10</p>
- <p class="TypedExample">print x</p>
- <p class="Stepnonumbering"> </p>
- <p class="Stepnonumbering">After this step, the console window will contain
- the following text:</p>
- <p class="Code-Highlighted">>>> 2+2</p>
- <p class="Code-Background">4</p>
- <p class="Code-Highlighted">>>> print "Hello World!"</p>
- <p class="Code-Background">Hello World!</p>
- <p class="Code-Highlighted">>>> for i in range(3): print i</p>
- <p class="Code-Highlighted">...</p>
- <p class="Code-Background">0<br />
- 1<br />
- 2</p>
- <p class="Code-Highlighted">>>> x = 10<br />
- >>> print x</p>
- <p class="Code-Background"></p>
- <p class="Code-Background">10</p>
- <p class="Code-Highlighted">>>> </p>
- <ol start="3">
- <li>
- <p class="Step">The IronPython console supports multi-line statements, often
- used in function or class definitions. IronPython prompts for additional lines in a
- multi-line statement using:</p>
- </li>
- </ol>
- <p class="Code-Highlighted">...</p>
- <p class="Code-Background"></p>
- <p class="Body"> </p>
- <p class="Stepnonumbering">One of the more unique aspects of Python is its sensitivity to whitespace at the
- beginning of a line. Unlike C, C# or Java, where blocks of code are grouped by curly brackets "{...}",
- blocks of code in Python are grouped based on their level of indentation. Every new block of code
- must be indented one more level than the previous block of code. Blocks of code are used for many
- constructs, including function and class definitions, the bodies of loops, 'if'...'elif'...'else' clauses,
- and 'try'...'except'...'finally' blocks. </p>
- <p class="Stepnonumbering">Define the 'add' function (note, you
- need to enter spaces before the 'return' statement):</p>
- <p class="TypedExample">def add(a, b):<br>
- return a + b</p>
- <p class="Stepnonumbering">To complete the function definition, press Enter
- once more at this point</p>
- <p class="TypedExample">add(3, 2)</p>
- <p class="TypedExample">add('Iron', 'Python')</p>
- <p class="Stepnonumbering"> </p>
- <p class="Stepnonumbering">After this step, the console contents will be:</p>
- <p class="Code-Highlighted">>>> def add(a, b):<br />
- ... return a + b<br />
- ...<br />
- >>> add(3, 2)</p>
- <p class="Code-Background">5</p>
- <p class="Code-Highlighted">>>> add("Iron", "Python")</p>
- <p class="Code-Background">'IronPython'</p>
- <p class="Code-Highlighted">>>> </p>
- <p class="Step"> </p>
- <ol start="4">
- <li>
- <p class="Step">To exit the IronPython interactive console, type Ctrl+Z and Enter (alternatively,
- press F6 followed by Enter).</p>
- </li>
- </ol>
- <p class="TypedExample">^Z</p>
- <h3><a name="T1.1.2">Task 2: Built-in modules and interactive exploration</a></h3>
- <ol>
- <li>
- <p class="Step">Start the IronPython console from the tutorial directory
- (see <a href="#Intro">Introduction</a> for details).</p>
- </li>
- <li>
- <p class="Step">Using the built-in function dir(), list the contents of
- the IronPython environment:</p>
- </li>
- </ol>
- <p class="TypedExample">dir()</p>
- <p class="Stepnonumbering">The output in the console window will be:</p>
- <p class="Code-Highlighted">>>> dir()</p>
- <p class="Code-Background">['__builtins__', '__doc__', '__name__']<br />
- </p>
- <ol start="3">
- <li>
- <p class="Step">IronPython comes with several built-in modules including 'sys', which is
- one of the most frequently used. Load the 'sys' module using the 'import' keyword:</p>
- </li>
- </ol>
- <p class="TypedExample">import sys</p>
- <ol start="4">
- <li>
- <p class="Step">The Python 'import' statement is similar to the 'using' statement
- of C# or 'Imports' statement of Visual Basic. The important difference is
- that the C# and VB statements bring the names from the imported namespace
- into the global namespace to be accessed directly. Python’s import doesn’t
- do that automatically, unless it is used in conjunction with the 'from'
- keyword (more on this later). To access the names or attributes in an imported
- module, prefix them with the module's name:</p>
- </li>
- </ol>
- <p class="UserExample">sys.version</p>
- <ol start="5">
- <li>
- <p class="Step">Use the dir() function to explore the environment:</p>
- </li>
- </ol>
- <p class="TypedExample">dir()</p>
- <p class="Stepnonumbering" style="margin-left: 0.5in">The environment (global namespace) has changed, now
- it contains the 'sys' module:</p>
- <p class="Code-Highlighted">>>> dir()</p>
- <p class="Code-Background">['__builtins__', '__doc__', '__name__', 'sys']</p>
- <ol start="6">
- <li>
- <p class="Step">Use the dir() function to explore the contents of the 'sys'
- module:</p>
- </li>
- </ol>
- <p class="TypedExample">dir(sys)</p>
- <p class="HiddenOutput">['__doc__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dllhandle', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_traceback', 'exc_type', 'exc_value', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'getcheckinterval', 'getdefaultencoding', 'getfilesystemencoding', 'getrecursionlimit', 'getsizeof', 'gettrace', 'getwindowsversion', 'hexversion', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'py3kwarning', 'setcheckinterval', 'setdefaultencoding', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions', 'winver']</p>
- <ol start="7">
- <li>
- <p class="Step">Print the values of some of the 'sys' module attributes:</p>
- </li>
- </ol>
- <p class="TypedExample">sys.path</p>
- <p class="LooseVerify">['.', '%DLR_ROOT%\\Test', '%DLR_ROOT%\\Languages\\IronPython\\Public\\Tutorial', '%DLR_ROOT%\\Languages\\IronPython\\Tests', '%DLR_ROOT%\\Test\\IronPythonTutorial', '%DLR_ROOT%\\bin\\Debug\\Lib', '%DLR_ROOT%\\bin\\Debug\\DLLs', '%DLR_ROOT%\\bin\\Debug']</p>
- <p class="TypedExample">sys.executable</p>
- <p class="LooseVerify">'%DLR_ROOT%\\bin\\Debug\\ipy.exe'</p>
- <h3><a name="T1.1.3">Task 3: External Python modules</a></h3>
- <p class="Normal">This task uses the module 'first.py' located in the Tutorial
- folder.</p>
- <ol>
- <li>
- <p class="Step">Import the 'first.py' module located in the Tutorial directory:</p>
- </li>
- </ol>
- <p class="TypedExample">import first</p>
- <p class="Code-Background"></p>
- <p class="Stepnonumbering">Because you launched ipy.exe from there, the Tutorial directory appears
- in sys.path, telling IronPython to look there in its search for 'first.py'.</p>
- <ol start="2">
- <li>
- <p class="Step">Explore the 'first' module using dir():</p>
- </li>
- </ol>
- <p class="TypedExample">dir(first)</p>
- <p class="Code-Highlighted">>>> dir(first)</p>
- <p class="Code-Background">['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'add', 'factorial', 'hi']</p>
- <ol start="3">
- <li>
- <p class="Step">Print the documentation for the 'add' and 'factorial' functions,
- using __doc__ attribute:</p>
- </li>
- </ol>
- <p class="TypedExample">first.add.__doc__</p>
- <p class="TypedExample">first.factorial.__doc__</p>
- <p class="Stepnonumbering"> </p>
- <p class="Stepnonumbering">We will use the __doc__ attribute later to explore .NET
- methods and their parameter types.</p>
- <p class="Code-Highlighted">>>> first.add.__doc__</p>
- <p class="Code-Background">'add(a, b) -> returns a + b'</p>
- <p class="Code-Highlighted">>>> first.factorial.__doc__</p>
- <p class="Code-Background">'factorial(n) -> returns factorial of n'</p>
- <ol start="4">
- <li>
- <p class="Step">Call the methods in the 'first' module and print the contents
- of the 'hi' attribute</p>
- </li>
- </ol>
- <p class="TypedExample">first.add(1,2)</p>
- <p class="TypedExample">first.factorial(5)</p>
- <p class="TypedExample">first.hi</p>
- <p class="Stepnonumbering">The expected output is:</p>
- <p class="Code-Highlighted">>>> first.add(1,2)</p>
- <p class="Code-Background">3</p>
- <p class="Code-Highlighted">>>> first.factorial(5)</p>
- <p class="Code-Background">120</p>
- <p class="Code-Highlighted">>>> first.hi</p>
- <p class="Code-Background">'Hello from IronPython!'</p>
- <ol start="5">
- <li>
- <p class="Step">Exit the IronPython Interactive console (Ctrl+Z or F6 followed
- by Enter)</p>
- </li>
- </ol>
- <h2><a name="T1.2">Exercise 2: Using the standard .NET libraries from IronPython</a></h2>
- <p class="Body">Much of IronPython's power arises from its ability to seamlessly
- access the wealth of .NET libraries. This exercise will demonstrate how the
- .NET libraries can be used from IronPython.</p>
- <p class="Body">In this exercise, you will use the standard .NET libraries from
- IronPython. </p>
- <h3><a name="T1.2.1">Task 1: Basic .NET library use</a></h3>
- <ol>
- <li>
- <p class="Step">Start the IronPython console from the tutorial directory
- (see <a href="#Intro">Introduction</a> for details).</p>
- </li>
- <li>
- <p class="Step">Using the 'import' keyword, import the .NET System namespace:</p>
- </li>
- </ol>
- <p class="TypedExample">import System</p>
- <p class="Code-Background"></p>
- <ol start="3">
- <li>
- <p class="Step">Explore the System.Environment class and access some of
- its properties:</p>
- </li>
- </ol>
- <p class="TypedExample">dir(System.Environment)</p>
- <p class="UserCode">System.Environment.OSVersion</p>
- <p class="TypedExample">System.Environment.CommandLine</p>
- <p class="Stepnonumbering"> </p>
- <p class="Stepnonumbering">The expected output of these commands is as follows
- (with ellipsis for convenience):</p>
- <p class="Code-Highlighted">>>> dir(System.Environment)</p>
- <p class="HiddenOutput">['CommandLine','CurrentDirectory','Equals','Exit','ExitCode','ExpandEnvironmentVariables','FailFast','GetCommandLineArgs','GetEnvironmentVariable','GetEnvironmentVariables','GetFolderPath','GetHashCode','GetLogicalDrives','GetType','HasShutdownStarted','Is64BitOperatingSystem','Is64BitProcess','MachineName','MemberwiseClone','NewLine','OSVersion','ProcessorCount','ReferenceEquals','SetEnvironmentVariable','SpecialFolder','SpecialFolderOption','StackTrace','SystemDirectory','SystemPageSize','TickCount','ToString','UserDomainName','UserInteractive','UserName','Version','WorkingSet','__all__','__class__','__delattr__','__doc__','__format__','__getattribute__','__hash__','__init__','__new__','__reduce__','__reduce_ex__','__repr__','__setattr__','__sizeof__','__str__','__subclasshook__']</p>
- <p class="NoVerify-Background">['CommandLine', 'CurrentDirectory', ... '__subclasshook__']</p>
- <p class="Code-Highlighted">>>> System.Environment.OSVersion</p>
- <p class="NoVerify-Background"><System.OperatingSystem object at 0x000000000000002B [Microsoft Windows NT 6.0.6000.0]</p>
- <p class="Code-Highlighted">>>> System.Environment.CommandLine</p>
- <p class="LooseVerify">'"%DLR_ROOT%\\Bin\\Debug\\ipy.exe"'</p>
- <p class="NoVerify-Background">'C:\\IronPython\\ipy.exe'</p>
- <ol start="4">
- <li>
- <p class="Step">The import statement can also be used to import contents of
- a class or module into the global namespace. Use the "from ... import ..."
- flavor of the import statement to do this, then use dir() to explore the contents of the
- global namespace.</p>
- </li>
- </ol>
- <p class="TypedExample">from System.Math import *</p>
- <p class="UserCode">dir()</p>
- <p class="HiddenCode">set1 = set(dir())
- set2 = set(dir(object))
- list(set1-set2)
- </p>
- <p class="HiddenOutput">
- ['Tan','Sin','Ceiling','Sinh','Atan','Tanh','__name__','Pow','Cos','Cosh','Abs','Round','Atan2','BigMul','Acos','DivRem','Truncate','E','Max','__builtins__','Log','Asin','Floor','PI','Log10','System','Sign','Exp','Min','IEEERemainder','Sqrt']</p>
- <p class="Stepnonumbering">Now you can call Math methods without having to specify
- the namespace and class name prefix:</p>
- <p class="TypedExample">Sin(PI/2)</p>
- <p class="Stepnonumbering"> </p>
- <p class="Stepnonumbering">The expected output is:</p>
- <p class="Code-Highlighted">>>> from System.Math import *</p>
- <p class="Code-Highlighted">>>> dir()</p>
- <p class="NoVerify-Background">
- ['Abs', 'Acos', 'Asin', 'Atan', 'Atan2', 'BigMul', 'Ceiling', 'Cos', 'Cosh', 'DivRem', 'E', 'Equals', 'Exp', 'Floor', 'GetHashCode', 'GetType', 'IEEERemainder', 'Log', 'Log10', 'Max', 'Min', 'PI', 'Pow', 'Round', 'Sign', 'Sin', 'Sinh', 'Sqrt', 'System', 'Tan', 'Tanh', 'ToString', 'Truncate', '__builtins__', '__doc__', '__name__']</p>
- <p class="Code-Highlighted">>>> Sin(PI/2)</p>
- <p class="Code-Background">1.0</p>
- <h3><a name="T1.2.2">Task 2: Working with .NET classes</a></h3>
- <ol>
- <li>
- <p class="Step">Import the contents of the "System.Collections" namespace
- into the global namespace:</p>
- </li>
- </ol>
- <p class="TypedExample">from System.Collections import *</p>
- <p class="Code-Background"></p>
- <ol start="2">
- <li>
- <p class="Step">Create instance of the Hashtable class and explore the instance
- using dir():</p>
- </li>
- </ol>
- <p class="TypedExample">h = Hashtable()</p>
- <p class="Code-Background"></p>
- <p class="UserCode">dir(h)</p>
- <p class="HiddenCode">set1 = set(dir(h))
- set2 = set(dir(object))
- list(set1-set2)</p>
- <p class="HiddenOutput">
-
- ['Keys','GetObjectData','Count','Contains','__getitem__','KeyEquals','hcp','Clone','SyncRoot','__setitem__','Remove','Clear','comparer','__len__','ContainsValue','Add','__add__','EqualityComparer','GetHash','IsFixedSize','ContainsKey','CopyTo','GetEnumerator','Synchronized','__iter__','IsReadOnly','__contains__','Item','Values','IsSynchronized','OnDeserialization']</p>
- <ol start="3">
- <li>
- <p class="Step">Insert a few elements into the hash table:</p>
- </li>
- </ol>
- <p class="TypedExample">h['a'] = 'IronPython'</p>
- <p class="Code-Background"></p>
- <p class="TypedExample">h['b'] = 'Tutorial'</p>
- <p class="Code-Background"></p>
- <p class="Stepnonumbering"> </p>
- <p class="Stepnonumbering">IronPython supports the C#-style syntax for accessing
- the hash table elements. The same syntax applies to any indexable object (Arrays,
- Array lists etc):</p>
- <p class="TypedExample">h['a']</p>
- <p class="Stepnonumbering" style="page-break-after:avoid"> </p>
- <p class="Stepnonumbering" style="page-break-after:avoid">The output of this
- step will be:</p>
- <p class="NoVerify-Highlighted" style="page-break-after:avoid">>>> h['a'] = 'IronPython'<br />
- >>> h['b'] = 'Tutorial'</p>
- <p class="Code-Highlighted" style="page-break-after:avoid">>>> h['a']</p>
- <p class="Code-Background">'IronPython'</p>
- <ol start="4">
- <li>
- <p class="Step">Enumerate the contents of the hash table using the "for
- ... in ..." statement. The hash table elements are instances of "DictionaryEntry"
- class. Print the "Key" and "Value" properties of each entry:</p>
- </li>
- </ol>
- <p class="TypedExample">for e in h: print e.Key, ':', e.Value</p>
- <p class="Stepnonumbering"> </p>
- <p class="Stepnonumbering">The expected output in the console is as follows. Note that
- the input line starting with 'for' requires an extra return or enter key press because
- the interpreter prompts for more statements in the loop's body.</p>
- <p class="Code-Highlighted">>>> for e in h: print e.Key, ':', e.Value<br>
- ...</p>
- <p class="Code-Background">a : IronPython<br />
- b : Tutorial</p>
- <ol start="5">
- <li>
- <p class="Step">You can initialize the collection classes using instances
- of the built-in list or tuple data types as arguments. You can
- create a Python list by specifying the list of elements in square brackets: [1,2,3].
- You create tuples by specifying elements in the parentheses: (1,2,3).</p>
- </li>
- </ol>
- <p class="TypedExample">l = ArrayList([1,2,3])</p>
- <p class="Code-Background"></p>
- <p class="TypedExample">for i in l: print i</p>
- <p class="TypedExample">s = Stack((1,2,3))</p>
- <p class="TypedExample">while s.Count: s.Pop()</p>
- <p class="Stepnonumbering"> </p>
- <p class="Stepnonumbering">The expected output is:</p>
- <p class="Code-Highlighted">>>> l = ArrayList([1,2,3])<br />
- >>> for i in l: print i<br>
- ...</p>
- <p class="Code-Background">1<br />
- 2<br />
- 3</p>
- <p class="Code-Background"></p>
- <p class="Code-Highlighted">>>> s = Stack((1,2,3))<br />
- >>> while s.Count: s.Pop()<br>...</p>
- <p class="Code-Background">3<br />
- 2<br />
- 1</p>
- <h3><a name="T1.2.3">Task 3: Generics</a></h3>
- <ol>
- <li>
- <p class="Step">Import the Generic collections from the System.Collections.Generic
- namespace:</p>
- </li>
- </ol>
- <p class="TypedExample">from System.Collections.Generic import *</p>
- <p class="Code-Background"></p>
- <ol start="2">
- <li>
- <p class="Step">To instantiate a generic class, the generic type arguments
- must be specified. IronPython uses the following syntax to specify the type
- arguments: generic_type[type_argument, ...]. Create an instance of generic
- list of string:</p>
- </li>
- </ol>
- <p class="TypedExample">l = List[str]()</p>
- <p class="Code-Background"></p>
- <ol start="3">
- <li>
- <p class="Step">Add string values into the list. Since we created a list of
- string, adding strings is possible:</p>
- </li>
- </ol>
- <p class="TypedExample">l.Add("Hello")</p>
- <p class="Code-Background"></p>
- <p class="TypedExample">l.Add("Hi")</p>
- <p class="Code-Background"></p>
- <ol start="4">
- <li>
- <p class="Step">Try adding objects of types other than string:</p>
- </li>
- </ol>
- <p class="ExceptionExample">l.Add(3)</p>
- <p class="Code-Background"></p>
- <p class="ExceptionExample">l.Add(2.5)</p>
- <p class="Code-Background"></p>
- <p class="ExceptionExample">l.Add([1,2,3])</p>
- <p class="Code-Background"></p>
- <p class="Stepnonumbering"> </p>
- <p class="Stepnonumbering">Obviously, adding non-strings will result in a type error:</p>
- <p class="Code-Highlighted">>>> l.Add(3)</p>
- <p class="NoVerify-Background">Traceback (most recent call last):<br />
- File "<stdin>", line 1, in <module><br />
- TypeError: expected str, got int<br /></p>
- <p class="Code-Highlighted">>>> l.Add(2.5)</p>
- <p class="NoVerify-Background">Traceback (most recent call last):<br />
- File "<stdin>", line 1, in <module><br />
- TypeError: expected str, got float<br /></p>
- <p class="Code-Highlighted">>>> l.Add([1,2,3])</p>
- <p class="NoVerify-Background">Traceback (most recent call last):<br />
- File "<stdin>", line 1, in <module><br />
- TypeError: expected str, got list<br /></p>
- <ol start="5">
- <li>
- <p class="Step">Enumerate the generic collection:</p>
- </li>
- </ol>
- <p class="TypedExample">for i in l: print i</p>
- <p class="Stepnonumbering"> </p>
- <p class="Stepnonumbering">The output will be:</p>
- <p class="Code-Highlighted">>>> for i in l: print i<br>...</p>
- <p class="Code-Background">Hello<br />
- Hi</p>
- <p class="ExceptionOutput">TypeError: expected str, got int
- TypeError: expected str, got float
- TypeError: expected str, got list</p>
- <ol start="6">
- <li>
- <p class="Step">Exit the IronPython Interactive console (Ctrl+Z or F6 followed
- by Enter)</p>
- </li>
- </ol>
- <h2><a name="T1.3">Exercise 3: Loading additional .NET libraries</a></h2>
- <p class="Body">IronPython can directly import only some of the .NET libraries
- - the most commonly used ones. To use additional .NET libraries, they must be
- explicitly referenced. IronPython maintains a list of all referenced
- assemblies (see clr.References in Task 1). To add a reference to a .NET assembly,
- use the functions available in the built-in 'clr' module:</p>
- <ul>
- <li>
- <p class="Body"><b>clr.AddReference</b> adds a reference to the .NET assembly
- either by passing the .NET assembly object directly, or specifying the file
- name or the assembly name (full or partial). This function is provided primarily
- for the kind of interactive exploration we see in this Tutorial. We recommend
- using the following functions in your code modules, since they provide more control
- over which assembly gets loaded.</p>
- </li>
- <li>
- <p class="Body"><b>clr.AddReferenceToFile</b> adds a reference to the assembly
- specified by its file name. This function will load the assembly from the
- file regardless of the assembly version. As a result, it doesn't guarantee
- that the correct assembly version is being loaded. To guarantee that correct
- assembly version is being loaded, use clr.AddReferenceByName. Moreover,
- AddReferenceToFile requires that the assembly be located in a
- directory listed in sys.path.</p>
- </li>
- <li>
- <p class="Body"><b>clr.AddReferenceToFileAndPath</b> provides similar
- functionality to AddReferenceToFile. The difference is that it accepts
- absolute path and before loading the assembly, AddReferenceToFileAndPath
- adds the file path into sys.path.</p>
- </li>
- <li>
- <p class="Body"><b>clr.AddReferenceByName</b> adds a reference to the assembly
- specified by its full assembly name, for example: "System.Xml, Version=2.0.0.0,
- Culture=neutral, PublicKeyToken=b77a5c561934e089".</p>
- </li>
- <li>
- <p class="Body"><b>clr.AddReferenceByPartialName</b> adds reference to the
- assembly by specifying a partial assembly name. This function cannot guarantee
- that the correct version of the assembly is being loaded. Use clr.AddReferenceByName
- to reference a specific version of the assembly.</p>
- </li>
- </ul>
- <h3><a name="T1.3.1">Task 1: Using System.Xml - AddReference</a></h3>
- <ol>
- <li>
- <p class="Step">Start the IronPython console from the tutorial directory
- (see <a href="#Intro">Introduction</a> for details).</p>
- </li>
- <li>
- <p class="Step">To import System.Xml, the reference to the assembly containing
- the Xml components must be first added to IronPython. Reference System.Xml
- using the following code (you can enter "clr.References" before
- and after the call to "clr.AddReference" to see it change if you want):</p>
- </li>
- </ol>
- <p class="TypedExample">import clr</p>
- <p class="Code-Background"></p>
- <p class="TypedExample">clr.AddReference('System.Xml')</p>
- <p class="Code-Background"></p>
- <p class="TypedExample">from System.Xml import *</p>
- <p class="Code-Background"></p>
- <p class="TypedExample">dir()</p>
- <p class="HiddenOutput">['ConformanceLevel','DtdProcessing','EntityHandling','Formatting','IHasXmlNode','IXmlLineInfo','IXmlNamespaceResolver','NameTable','NamespaceHandling','NewLineHandling','ReadState','Resolvers','Schema','Serialization','ValidationType','WhitespaceHandling','WriteState','XPath','XmlAttribute','XmlAttributeCollection','XmlCDataSection','XmlCharacterData','XmlComment','XmlConvert','XmlDateTimeSerializationMode','XmlDeclaration','XmlDocument','XmlDocumentFragment','XmlDocumentType','XmlElement','XmlEntity','XmlEntityReference','XmlException','XmlImplementation','XmlLinkedNode','XmlNameTable','XmlNamedNodeMap','XmlNamespaceManager','XmlNamespaceScope','XmlNode','XmlNodeChangedAction','XmlNodeChangedEventArgs','XmlNodeChangedEventHandler','XmlNodeList','XmlNodeOrder','XmlNodeReader','XmlNodeType','XmlNotation','XmlOutputMethod','XmlParserContext','XmlProcessingInstruction','XmlQualifiedName','XmlReader','XmlReaderSettings','XmlResolver','XmlSecureResolver','XmlSignificantWhitespace','XmlSpace','XmlText','XmlTextReader','XmlTextWriter','XmlTokenizedType','XmlUrlResolver','XmlValidatingReader','XmlWhitespace','XmlWriter','XmlWriterSettings','Xsl','__builtins__','__doc__','__name__','clr']</p>
- <ol start="3">
- <li>
- <p class="Step">Note that the clr.AddReference function accepts either System.Reflection.Assembly object or string
- as a parameter. The string parameter can
- be a full assembly name, a partial assembly name, or a file name. For more control
- over the assembly references, use the appropriate functions described
- above. </p>
- <p class="Step">For example, consider the following alternatives for the statement clr.AddReference('System.Xml') above:</p>
- </li>
- </ol>
- <p class="TypedExample">clr.AddReferenceByName('System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')</p>
- <p class="Code-Background"></p>
- <p class="TypedExample">clr.AddReferenceByPartialName('System.Xml')</p>
- <p class="Code-Background"></p>
- <ol start="4">
- <li>
- <p class="Step">Load the XML file 'load.xml' into the XmlDocument. The
- xml file contains sample savegame data from the IronPython sample 'Puzzle' .
- For direct viewing, the load.xml file is located in the Tutorial folder</p>
- </li>
- </ol>
- <p class="TypedExample">d = XmlDocument()</p>
- <p class="Code-Background"></p>
- <p class="TypedExample">d.Load('load.xml')</p>
- <p class="Code-Background"></p>
- <ol start="5">
- <li>
- <p class="Step">We can now query the document. Query for all the saved games using the query below:</p>
- </li>
- </ol>
- <p class="TypedExample">n = d.SelectNodes('//Puzzle/SavedGames/Game/@caption')</p>
- <p class="TypedExample">for e in n: print e.Value</p>
- <p class="Stepnonumbering"> </p>
- <p class="Stepnonumbering">The output in the console window will be:</p>
- <p class="Code-Highlighted">>>> n = d.SelectNodes('//Puzzle/SavedGames/Game/@caption')<br />
- >>> for e in n: print e.Value<br>...</p>
- <p class="Code-Background">
- Seattle (default game)<br />
- New York<br />
- World<br />
- North America<br />
- </p>
- <ol start="6">
- <li>
- <p class="Step">(Optional) Import the 'xmlutil.py' module located in the
- Tutorial directory and use the function provided in the module to walk the
- contents of the Xml document:</p>
- </li>
- </ol>
- <p class="TypedExample">import xmlutil</p>
- <p class="TypedExample">for e in xmlutil.Walk(d): print e.Name, e.Value</p>
- <p class="HiddenOutput">#document None
- #comment *************************************************************************
- *
- * Copyright (c) Microsoft Corporation.
- *
- * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
- * copy of the license can be found in the License.html file at the root of this distribution. If
- * you cannot locate the Apache License, Version 2.0, please send an email to
- * ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
- * by the terms of the Apache License, Version 2.0.
- *
- * You must not remove this notice, or any other, from this software.
- *
- *
- * ***************************************************************************
- Puzzle None
- SavedGames None
- Game None
- caption Seattle (default game)
- type a
- y 714
- x 327
- level 11
- dimension 3
- Game None
- caption New York
- type r
- y 1538
- x 1205
- level 12
- dimension 3
- Game None
- caption World
- type h
- y 0
- x 0
- level 2
- dimension 4
- Game None
- caption North America
- type a
- x 2
- y 5
- level 4
- dimension 3
- TopLeftPreviewTile None
- x -3
- y -3
- dimension 3
- level 5
- Cache None
- allow true</p>
- <p class="Stepnonumbering">The Walk function is a generator (a Python function
- that contains a "yield" statement). As the Walk function executes, it returns
- (yields) the XML nodes one by one to the caller, who is iterating over the generator.
- The source for the Walk function is:</p>
- <p class="CodeSample">def Walk(xml):</br>
- yield xml</br><br>
- if hasattr(xml, "Attributes"):<br />
- attrs = xml.Attributes<br />
- if attrs:<br />
- for attr in attrs:</br>
-
- yield attr</br><br>
- for child in xml:<br />
- for c in Walk(child):</br>
-
- yield c</p>
- <ol start="7">
- <li>
- <p class="Step">Exit the IronPython Interactive console (Ctrl+Z or F6 followed
- by Enter)</p>
- </li>
- </ol>
- <h3><a name="T1.3.2">Task 2: Mapack - Loading the .NET libraries - AddReferenceToFile</a></h3>
- <p class="Normal">This task requires the Mapack.dll library for linear algebra computations.
- The library is not part of the IronPython distribution. See <a href="#Mapack">prerequisites</a>
- for download details.</p>
- <ol>
- <li>
- <p class="Step">Start the IronPython console from the tutorial directory
- (see <a href="#Intro">Introduction</a> for details).</p>
- </li>
- <li>
- <p class="Step">Use the clr.AddReferenceToFile function to load the Matrix
- library "Mapack.dll":</p>
- </li>
- </ol>
- <p class="TypedExample">import clr</p>
- <p class="Code-Background"></p>
- <p class="TypedExample">clr.AddReferenceToFile("Mapack.dll")</p>
- <p class="Code-Background"></p>
- <p class="TypedExample">from Mapack import *</p>
- <p class="Code-Background"></p>
- <p class="TypedExample">dir()</p>
- <p class="Stepnonumbering">The expected output will be:</p>
- <p class="Code-Highlighted">>>> import clr<br />
- >>> clr.AddReferenceToFile("Mapack.dll")<br />
- >>> from Mapack import *<br />
- >>> dir()</p>
- <p class="Code-Background">['CholeskyDecomposition', 'EigenvalueDecomposition', 'LuDecomposition', 'Matrix', 'QrDecomposition', 'SingularValueDecomposition', '__builtins__', '__doc__', '__name__', 'clr']</p>
- <p class="StepNoNumbering"></p>
- <p class="StepNoNumbering">If you're having trouble getting this to work, make sure
- Mapack.dll is on the search path. One easy way to do this is to copy Mapack.dll into
- the Tutorial direcroty (or whichever directory you're running IronPython from).</p>
- <ol start="3">
- <li>
- <p class="Step">Instantiate the Matrix class:</p>
- </li>
- </ol>
- <p class="ExceptionExample">m = Matrix()</p>
- <p class="Code-Background"></p>
- <p class="Stepnonumbering">Oops, bad arguments for the constructor. In the next
- step, you'll learn how to discover which constructors are available.</p>
- <p class="Code-Highlighted">Traceback (most recent call last):<br />
- File "<stdin>", line 1, in <module><br />
- TypeError: Matrix() takes at least 1 argument (0 given)</p>
- <ol start="4">
- <li>
- <p class="Step">Using the __doc__ attribute, find out information about
- Matrix constructors:</p>
- </li>
- </ol>
- <p class="TypedExample">print Matrix.__new__.__doc__</p>
- <p class="Code-Highlighted">>>> print Matrix.__new__.__doc__</p>
- <p class="Code-Background">__new__(cls: type, rows: int, columns: int)<br />
- __new__(cls:type, rows: int, columns: int, value: float)<br />
- __new__(cls:type, value: Array[Array[float]])
- </p>
- <ol start="5">
- <li>
- <p class="Step">Create instances of the Matrix class using the correct constructors
- and set some matrix elements manually. IronPython supports custom indexing
- on .NET classes. </p>
- </li>
- </ol>
- <p class="TypedExample">m = Matrix(2, 2, 1.2)</p>
- <p class="Code-Background"></p>
- <p class="TypedExample">n = Matrix(2,1)</p>
- <p class="Code-Background"></p>
- <p class="TypedExample">n[0,0] = 4</p>
- <p class="Code-Background"></p>
- <p class="TypedExample">print m</p>
- <p class="TypedExample">print n</p>
- <p class="Code-Highlighted">>>> m = Matrix(2, 2, 1.2)<br />
- >>> n = Matrix(2,1)<br />
- >>> n[0,0] = 4<br />
- >>> print m</p>
- <p class="Code-Background">1.2 0<br />
- 0 1.2<br />
- </p>
- <p class="Code-Highlighted">>>> print n</p>
- <p class="Code-Background">4<br />
- 0<br />
- </p>
- <ol start="6">
- <li>
- <p class="Step">(Optional) IronPython also supports overloaded operators.
- Matrix provides implementations of operators +, - (binary and unary), *,
- and equality. You can see the Python representation of these operators
- (__eq__, __add__, __mul__, __sub__, ...) using dir():</p>
- </li>
- </ol>
- <p class="UserCode">dir(m)</p>
- <p class="HiddenCode">set1 = set(dir(m))
- set2 = set(dir(object))
- list(set1-set2)</p>
- <p class="HiddenOutput">
-
- ['FrobeniusNorm','InfinityNorm','Rows','__neg__','__radd__','Columns','__getitem__','Symmetric','__rmul__','Inverse','__rsub__','Solve','Clone','__setitem__','Multiply','Submatrix','Subtract','Random','__eq__','Diagonal','Trace','Negate','Add','Determinant','Norm1','__sub__','__add__','Transpose','Square','Item','__mul__','__ne__']</p>
- <ol start="7">
- <li>
- <p class="Step">Make simple calculations with the matrices:</p>
- </li>
- </ol>
- <p class="TypedExample">print m * n</p>
- <p class="TypedExample">print n.Transpose() * m</p>
- <p class="TypedExample">print m * 3</p>
- <p class="TypedExample">print n + -n</p>
- <p class="Stepnonumbering">The expected output of this step is:</p>
- <p class="Code-Highlighted">>>> print m * n</p>
- <p class="Code-Background">4.8<br />
- 0<br /><br />
- </p>
- <p class="Code-Highlighted">>>> print n.Transpose() * m</p>
- <p class="Code-Background">4.8 0…
Large files files are truncated, but you can click here to view the full file