Guest User

Untitled

a guest
Aug 15th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. How to get a DLR representation from C#?
  2. if (obj is IronPython.Runtime.List) {
  3. repr = ((IronPython.Runtime.List)obj).__repr__(
  4. IronPython.Runtime.DefaultContext.Default);
  5. } else if (obj is IronPython.Runtime.PythonDictionary) {
  6. repr = ((IronPython.Runtime.PythonDictionary)obj).__repr__(
  7. IronPython.Runtime.DefaultContext.Default);
  8.  
  9. var engine = Python.CreateEngine();
  10. dynamic obj = engine.Execute("[1, 2, 3, 4, 5]");
  11. dynamic builtin = engine.GetBuiltinModule();
  12. string repr = builtin.str(obj);
  13.  
  14. string repr = (string)engine.Execute("str([1, 2, 3, 4, 5])");
  15.  
  16. string repr = IronPython.Runtime.Operations.PythonOps.ToString(obj);
  17.  
  18. var engine = Ruby.CreateEngine();
  19. string repr = (string)engine.Execute("[1, 2, 3, 4, 5].to_s");
Add Comment
Please, Sign In to add comment