Skip to content

Commit 5c634e3

Browse files
BCSharpslozier
andauthored
Update example in README.md (#1192)
* Update example in README.md * Update README.md Co-authored-by: slozier <slozier@users.noreply.github.com>
1 parent 9128f7f commit 5c634e3

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

README.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,49 @@ IronPython 3
66

77
IronPython is an open-source implementation of the Python programming language which is tightly integrated with .NET. IronPython can use .NET and Python libraries, and other .NET languages can use Python code just as easily.
88

9+
IronPython 3 targets Python 3, including the re-organized standard library, Unicode strings, and all of the other new features.
10+
11+
912
| **What?** | **Where?** |
1013
| --------: | :------------: |
1114
| **Windows/Linux/macOS Builds** | [![Build status](https://dotnet.visualstudio.com/IronLanguages/_apis/build/status/ironpython3)](https://dotnet.visualstudio.com/IronLanguages/_build/latest?definitionId=43) [![Github build status](https://github.com/IronLanguages/ironpython3/workflows/CI/badge.svg)](https://github.com/IronLanguages/ironpython3/actions?workflow=CI) |
1215
| **Downloads** | [![NuGet](https://img.shields.io/nuget/vpre/IronPython.svg)](https://www.nuget.org/packages/IronPython/3.4.0-alpha1) [![Release](https://img.shields.io/github/release/IronLanguages/ironpython3.svg?include_prereleases)](https://github.com/IronLanguages/ironpython3/releases/latest)|
1316
| **Help** | [![Gitter chat](https://badges.gitter.im/IronLanguages/ironpython.svg)](https://gitter.im/IronLanguages/ironpython) [![StackExchange](https://img.shields.io/stackexchange/stackoverflow/t/ironpython.svg)](http://stackoverflow.com/questions/tagged/ironpython) |
1417

1518

16-
Comparison of IronPython vs. C# for 'Hello World'
19+
## Examples
1720

18-
C#:
21+
The following C# program:
1922

2023
```cs
21-
System.Console.WriteLine("Hello World");
24+
using System.Windows.Forms;
25+
26+
MessageBox.Show("Hello World!", "Greetings", MessageBoxButtons.OKCancel);
2227
```
2328

24-
IronPython:
29+
can be written in IronPython as follows:
2530

2631
```py
27-
print("Hello World")
32+
import clr
33+
clr.AddReference("System.Windows.Forms")
34+
from System.Windows.Forms import MessageBox, MessageBoxButtons
35+
36+
MessageBox.Show("Hello World!", "Greetings", MessageBoxButtons.OKCancel)
2837
```
2938

30-
IronPython 3 targets Python 3, including the re-organized standard library, Unicode strings, and all of the other new features.
39+
Here is an example how to call Python code from a C# program.
40+
41+
```cs
42+
var eng = IronPython.Hosting.Python.CreateEngine();
43+
var scope = eng.CreateScope();
44+
eng.Execute(@"
45+
def greetings(name):
46+
return 'Hello ' + name.title() + '!'
47+
", scope);
48+
dynamic greetings = scope.GetVariable("greetings");
49+
System.Console.WriteLine(greetings("world"));
50+
```
51+
This example assumes that `IronPython` has been added to the C# project as a NuGet package.
3152

3253
## Code of Conduct
3354
This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community.

0 commit comments

Comments
 (0)