Browse DevX
Sign up for e-mail newsletters from DevX


Python + .NET = IronPython : Page 3

IronPython brings the interactivity and productivity of the Python language to the.NET world.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Why Python?
Python is a language of shortcuts. Things that take multiple lines of code in other languages take fewer lines in Python. String manipulation is a particularly strong suit for Python. When defining a string both single and double quotes work. To escape special characters such as carriage return you must use the backslash (\) character followed by the decimal equivalent. The concept of slices makes it easy to grab a part of a string as in:

>>> Str = 'This is a string' >>> Str[2:6] 'is i' >>>Str[-4] 'r'

When you need to build a really long string that spans several lines of text you can use the triple quote construct to surround the entire line as in:

VeryLongString = ''' Now is the time for all good men to come To the aid of their countrymen. '''

Strings can span multiple lines of text as long as they are enclosed in triple quotes.'''

While Python is a dynamic language it is still strongly typed in a sense—meaning every object has a type. Python includes a number of built-in types such as lists, tuples, and dictionaries for simplifying many traditional programming tasks. On the other hand you don't declare variables with a type as you do in other languages such as C# or Java. The Python interpreter takes care of that for you sometimes to a fault. If you use the same name for a variable in two different parts of a program the first gets overwritten by the second—an obvious potential for hard-to-find bugs.

As a scripting language Python does the job of letting you build quick little programs in a short amount of time and test them interactively to make sure they work correctly. The Python library includes a multitude of pre-defined functions that make the job of coding much easier. You can also find numerous sample examples code on the Web, including code for such tasks as automating Word and Excel, interacting with Active Directory, and accessing the Windows Management Interface (WMI).

.NET Python
Figure 1. IronPython Console: The IronPython Console app provides an interactive interpreter where you can try out parts of the language.
The first public mention of IronPython was at the PyCON conference held in March of 2004 in Washington, DC. In this paper, Jim Hugunin describes the work he did to implement the full semantics of the Python language on top of the Common Language Runtime—either Microsoft's .NET version or the Mono platform. The paper goes on to describe his research and the test results.

Early implementations of IronPython worked on version 1.1 of the .NET runtime. Later releases target the upcoming version (2.0). As of this writing the latest IronPython version is 0.7.5 and requires the .NET Framework Version 2.0 Redistributable Package Beta 2.

The interactive console includes a built-in command (dir) that lists all the functions within a module. Figure 1 shows a list of all the functions included in the sys module. Python's help function has not been implemented in this version of IronPython.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date