HI Tiago - <br><br>If I'm reading this right, I think the issue is that your method is returning <br>a (Python) Template instance.<br><br>The PythonNet runtime can't convert arbitrary Python types to anything <br>that .NET can make sense of, so your method need to either return a 
<br>&quot;primitive&quot; Python type that maps to a primitive .NET type (string, int, <br>etc.), or a wrapped .NET object.<br><br>Try returning str(template), and I bet you'll get the string result on the <br>other side.
<br><br>Hope this helps,<br><br>Brian<br><br><div><span class="gmail_quote">On 5/10/06, <b class="gmail_sendername">Tiago Matias</b> &lt;<a href="mailto:tiago.matias@gmail.com">tiago.matias@gmail.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>Hi all!<br><br>I'm trying to invoke a python function from a .NET application. The C# code is this:
<br><br>
<div style="margin-left: 40px;">string templateFile = &quot;Simple.tpl&quot;;<br>
</div>


<div style="margin-left: 40px;">PythonEngine.Initialize();<br>
<br>
PyObject module = PythonEngine.ImportModule(&quot;Engine&quot;);<br>
PyObject method = module.GetAttr(&quot;FillTemplate&quot;);<br>
PyObject result = method.Invoke(PyObject.FromManagedObject(templateFile));<br>
<br>
Console.WriteLine(result.ToString());<br>
</div>
<br>
and the python module is simply:<br>
<br>
<div style="margin-left: 40px;">from Cheetah.Template import Template<br>
<br>
def FillTemplate(templateName):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; template = Template(file=templateName)<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return template<br>
<br>
</div>
<br>
Now, the problem is the parameter. If I hardcode &quot;Simple.tpl&quot; in the
constructor everything works as expected. Also, if I change the python
code to &quot;return templateName&quot; I get &quot;Simple.tpl&quot; back in the C# code.<br>
<br>
But, if I run the code above a PythonException is thrown....I've also
tried to place a try...except block around the code but it didn't
caught any exception... I suspect that I must be calling the
PyObject.Invoke() function with the wrong arguments...<br>
<br>
Essentially the purpose of this is to generate C# code with the help of
cheetah templates. The ideia is to construct an object containing the
metadata and then pass it to cheetah to generate code.<br>
<br>
But I can't seem to be able to pass a simple string!<br>
<br>
Any help would be grealty appreciated! Btw, bear in mind that this is
my first attempt with python... so the question maybe stupid ;)<br>
<br>
<br>
Thanks in advance!<br></div><div><span class="sg">
<br>
Tiago<br>

</span></div><br>_________________________________________________<br>Python.NET mailing list - <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:PythonDotNet@python.org">PythonDotNet@python.org</a><br>
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.python.org/mailman/listinfo/pythondotnet" target="_blank">http://mail.python.org/mailman/listinfo/pythondotnet</a><br><br></blockquote></div><br>