Your SlideShare is downloading. ×
Python with dot net and vs2010
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Python with dot net and vs2010

2,044
views

Published on

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,044
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
30
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Python with DotNet and VS2010
  • 2. Python tools for VisualStudio2010
    • http://pytools.codeplex.com/
  • 3.
    • Python Tools for Visual Studio turns Visual Studio into a Python IDE.  It's a free & open source plug-in for Visual Studio 2010 from Microsoft's Developer Division.
    • PTVS enables developers to use all the major productivity features of Visual Studio to build Python code using either CPython or IronPython and adds new features such as using High Performance Computing clusters to scale your code.
  • 4. IronPython
    • http://ironpython.codeplex.com/
      • Latest version 2.7.1
  • 5.
    • IronPython is an implementation of the  Python programming language  running under  .NET / Mono  and  Silverlight / Moonlight .
    • It supports an interactive console with fully dynamic compilation. It's well integrated with the rest of the .NET Framework and makes all .NET libraries easily available to Python programmers, while maintaining compatibility with the Python language. There also is Visual Studio tooling integration.
    • IronPython  is an open source project freely available under the Apache License v2.0. The sources are stored on GitHub as part of the  IronLanguages project.
  • 6. Usage
    • Use IronPython as scripting of DotNet
  • 7.  
  • 8.
    • Code example that adds reference
  • 9.  
  • 10.
    • d = XmlDocument()
    • d.Load('load.xml')
    • n = d.SelectNodes('//Puzzle/SavedGames/Game/@caption')
    • for e in n: print e.Value
  • 11.
    • Code example: WPF
  • 12.  
  • 13.
    • http://ironpython.net/documentation/dotnet/dotnet.html
  • 14. Using IronPython in C#
    • using System;
    • using IronPython.Hosting;
    • public class HelloWorld {
    • public static void Main(string[] args) {
    • var engine = Python.CreateEngine();
    • engine.CreateScriptSourceFromString("print 'hello world'").Execute();
    • }
    • }
  • 15. DotNet4 dynamic class Calculator(object): def add(self, a, b): return a + b ======================= string scriptPath = "Calculator.py"; ScriptEngine engine = Python.CreateEngine(); engine.SetSearchPaths(new string[] { … ScriptSource source = engine.CreateScriptSourceFromFile(scriptPath); ScriptScope scope = engine.CreateScope(); ObjectOperations op = engine.Operations; source.Execute(scope); dynamic Calculator = scope.GetVariable("Calculator"); dynamic calc = Calculator(); return calc.add(x,y);
  • 16. Create assembly with IronPython
    • Create C# project, add PythonEngine in code
    • Load python code file or resource string
    • Run the PythonEngine
  • 17. Subclassing .NET types
    • class MyClass(System.ICloneable):
    • pass
    • o = MyClass()
    • import clr
    • clr.GetClrType(System.ICloneable).IsAssignableFrom(o.GetType())
      • Output>>>True
    • class MyClass(System.ICloneable):
    • def Clone(self):
    • return MyClass()
    • o = MyClass()
    • o.Clone()
  • 18. Methods with multiple overloads
    • import clr
    • import System
    • StringComparer = System.Collections.Generic.IEqualityComparer[str]
    • class MyComparer(StringComparer):
    • def GetHashCode(self, *args):
    • if len(args) == 0:
    • # Object.GetHashCode() called
    • return 100
    • if len(args) == 1 and type(args[0]) == str:
    • # StringComparer.GetHashCode() called
    • return 200
    • assert("Should never get here")
    • comparer = MyComparer()
    • getHashCode1 = clr.GetClrType(System.Object).GetMethod("GetHashCode")
    • args = System.Array[object](["another string"])
    • getHashCode2 = clr.GetClrType(StringComparer).GetMethod("GetHashCode")
    • # Use Reflection to simulate a call to the different overloads
    • # from another .NET language
    • getHashCode1.Invoke(comparer, None)
    • >>>100
    • getHashCode2.Invoke(comparer, args)
  • 19. Winform example
  • 20.  
  • 21. IronTunes – WPF example
    • http://ironpython.codeplex.com/releases/view/12482
  • 22. App and ViewModel
  • 23.  
  • 24. Diskusage - WPF
  • 25.  
  • 26. IronPython with SilverLight http://www.silverlight.net/learn/advanced-techniques/dynamic-languages/dynamic-languages-in-silverlight#example_applications

×