Wrapping a Stream in Python file

When hosting, there are times when you have a Stream on the .NET Side and need to pass it to Python as a file-like object. There is no straightforward way to do this, but there is a quick workaround:

private static object MakePythonFile(ScriptEngine engine, System.IO.Stream stream) {   return engine.Operations.Call(        engine.CreateScriptSourceFromString("__builtins__['file']").Execute,        stream    ); }