将 IronPython 文件对象转换为 .NET Stream 对象

发布于 2024-10-10 10:51:55 字数 289 浏览 0 评论 0原文

有没有一种简单的方法可以将 IronPython 文件类对象转换为 .NET Stream?在 IronPython 中可以使用如下代码完成相反的操作:

net_stream = File.OpenRead('file.txt')
python_file = file(net_stream)

是否有一种简单的方法将其转换回来?或者您是否必须编写一个从 Stream 继承并实现所有方法的包装器?

Is there an easy way to convert an IronPython file-like object to a .NET Stream? The reverse can be done in IronPython using code like this:

net_stream = File.OpenRead('file.txt')
python_file = file(net_stream)

Is there an easy way to convert it back? Or do you have to write a wrapper that will inherit from Stream and implement all the methods?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

显然可以这样做:

import System
f = file('abc.txt', 'w+')
f.GetType().GetField('_stream', System.Reflection.BindingFlags.Instance | 
                                System.Reflection.BindingFlags.NonPublic).GetValue(f)

apparently it's possible to do it like this:

import System
f = file('abc.txt', 'w+')
f.GetType().GetField('_stream', System.Reflection.BindingFlags.Instance | 
                                System.Reflection.BindingFlags.NonPublic).GetValue(f)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文