[IronPython] How to get ToString() working, and questions about GetSysModule() and GetClrModule()

Dino Viehland dinov at microsoft.com
Mon Sep 21 12:07:09 PDT 2009


Because this is on a per-module basis calling GetClrModule() won't affect the module you later want to do .ToString from.

I think the easiest way to do this would be to do:

var code = Engine.CreateScriptSourceFromString("import clr", SourceCodeKind.Statements).Compile();

and whenever you want a module to use import clr do:

code.Execute(_scope);

If you open a bug on CodePlex though we could look at adding an extension method like "scope.EnableClr()" or something along those lines that makes this simpler.



-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Thomas Gagne
Sent: Monday, September 21, 2009 12:00 PM
To: users at lists.ironpython.com
Subject: [IronPython] How to get ToString() working, and questions about GetSysModule() and GetClrModule()

We've hosted Python inside our C# application and all seems to work 
well.  Recently, one of our programmers has asked to use ToString inside 
a python expression.  I read online we need to import the "clr" to make 
that happen.

The code for kicking it off looks like:

_engine = Python.CreateEngine();
_scope = _engine.CreateScope();

I'm curious, if I want the Clr already-imported to a program can ask for 
a fixed-point's ToString("C"), am I supposed to be able to use the 
GetClrModule()?

Since both it and CreateScope() return scopes I thought I'd try using 
the scope returned by GetClrModule() to evaluate an expression.  
Suddenly, "True" no longer evaluated.  It had no binding.

Signed confused.
_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


More information about the Users mailing list