<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=WordSection1>

<p class=MsoNormal>I&#8217;m trying to set up a simple scripting environment
for non-programmers that can call into our C# codebase.<o:p></o:p></p>

<p class=MsoNormal>Python is a non-typed language, whereas C# is strongly
typed.&nbsp; This is one of the reasons IronPython was written.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>It seems that the solution presented by IronPython is to
expose .NET types into Python.&nbsp; If I want to call a C# function that takes
an array of doubles as an argument, I have a problem.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>I know you can do something like:<o:p></o:p></p>

<p class=MsoNormal>Import System<o:p></o:p></p>

<p class=MsoNormal>Array=System.Array[float](range(10))&nbsp; <o:p></o:p></p>

<p class=MsoNormal>To create and initialize the array with a sequence of
numbers.&nbsp; But now you are working with a .NET variable, not a Python
variable.<o:p></o:p></p>

<p class=MsoNormal>I can also do something similar with lists.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>I don&#8217;t want to bring variable typing into Python,
because then it&#8217;s not Python.&nbsp; I also don&#8217;t want my users to
have to worry about this extra typing and keeping straight which variables need
it and which don&#8217;t.<o:p></o:p></p>

<p class=MsoNormal>I think the IronPython.Runtime should take care of this, but
it doesn&#8217;t.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>I&#8217;m willing to write wrappers, in C#, for all the
functions (if needed) that I want to expose to Python. I&#8217;ve been knocking
myself out trying to do this.&nbsp; <o:p></o:p></p>

<p class=MsoNormal>I&#8217;ve been trying to accept a non-typed list, and use
it to fill an array of doubles.&nbsp; In my trial and error attempts, I&#8217;ve
prototyped my argument as <o:p></o:p></p>

<p class=MsoNormal>Public static void TestIt(IList inList) and public static
void TestIt(IronPython.runtime.List inList).&nbsp; They both act pretty much
the same. I&#8217;ve also tried using tuples.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>If my python list is created with&nbsp; pyList=range(10),
then passed as an argument<o:p></o:p></p>

<p class=MsoNormal>No matter what I do, I&#8217;ve been unsuccessful filling my
array of doubles using<o:p></o:p></p>

<p class=MsoNormal>&nbsp; myDoubles[i] = (double)inList[i];&nbsp; (complains
that it can&#8217;t cast a value of infinity)<o:p></o:p></p>

<p class=MsoNormal>or any other type of casting I can come up with.<o:p></o:p></p>

<p class=MsoNormal>The debugger shows a nice list, with values 0-9.<o:p></o:p></p>

<p class=MsoNormal>inList[i].GetType() shows System.Int32.&nbsp; So why can&#8217;t
it cast?<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>As an aside, if I start with pyList=map(float,range(10)),
then&nbsp; GetType() returns System.double and the cast works without a problem(and
probably isn&#8217;t needed).<o:p></o:p></p>

<p class=MsoNormal>But this requires the user to once again worry about the
variable type.<o:p></o:p></p>

<p class=MsoNormal>Based on this, I&#8217;m pretty sure if I set up a switch
statement on type in my wrapper, and assign a temp variable with the same type,
then the cast of the temp variable it would work.<o:p></o:p></p>

<p class=MsoNormal>But this sure seems clumsy!<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Does anyone have an idea of how to do this?&nbsp; I&#8217;m
sure I just haven&#8217;t hit on the right combination.<o:p></o:p></p>

<p class=MsoNormal>Basically I want the user to be able to use pyList =
range(10) and let me worry about converting it to double in a C# wrapper if
that&#8217;s what is needed.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>I&#8217;m already resigned to writing wrappers in Python to
hide clr.Reference[type]() from my users when calling a C# functions that
requires an &#8220;out&#8221; or &#8220;ref&#8221; parameters.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Thanks in advance for reading a post that I *<b>know</b>* is
as much rant as question.&nbsp; It&#8217;s just been frustrating &#8230;.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal><b><span style='color:#1F497D'>Mark Senko<o:p></o:p></span></b></p>

<p class=MsoNormal><span style='color:#4F81BD'>Complete Genomics, Inc.<o:p></o:p></span></p>

<p class=MsoNormal>2071 Stierlin Court<o:p></o:p></p>

<p class=MsoNormal>Mountain View, CA 94043<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

</body>

</html>


<pre>

____ 
 
The contents of this e-mail and any attachments are confidential and only for 
use by the intended recipient. Any unauthorized use, distribution or copying 
of this message is strictly prohibited. If you are not the intended recipient 
please inform the sender immediately by reply e-mail and delete this message 
from your system. Thank you for your co-operation.</pre>