Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting IronPython file object to .NET Stream object

Tags:

ironpython

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?

like image 690
Can Gencer Avatar asked Dec 04 '25 06:12

Can Gencer


1 Answers

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)
like image 57
Can Gencer Avatar answered Dec 08 '25 01:12

Can Gencer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!