If you&#39;re willing to live on the bleeding edge and build from the latest sources, it turns out that Tomas just added this functionality to the hosting interfaces yesterday. ObjectOperations.Format(obj) should return a string that matches what the REPL would have printed.<br>
<br><div class="gmail_quote">On Tue, Jan 27, 2009 at 7:52 PM, Jeff Slutter <span dir="ltr">&lt;<a href="mailto:jslutter@reactorzero.com">jslutter@reactorzero.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Given an object, how can I go about printing out that object as a string<br>
representing the object in Python syntax?<br>
<br>
I need something a little more powerful than just object.ToString()<br>
<br>
I need something like how the interactive console reports the result of<br>
the statement.<br>
<br>
For instance:<br>
<br>
a = [0,1,2]<br>
b = [a,8,9]<br>
<br>
If I pass &#39;b&#39; to a function in C#, like:<br>
<br>
void SomeFunction( object obj )<br>
{<br>
 &nbsp; string objStr = ConvertToString( obj );<br>
 &nbsp; Console.Write( objStr );<br>
}<br>
<br>
it would print out:<br>
[[0,1,2],8,9]<br>
<br>
Obviously ToString() will work for simple things, but once I try to use<br>
lists or dictionaries it no longer works.<br>
<br>
Thank you,<br>
Jeff<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
</blockquote></div><br>