Hello, I am using Julia v1.8.5, Python v3.11.2, and juliacall v0.9.12. I am linking a Julia package to a Python web app and running into some issues with interoperability of StringIO objects. A MWE to demonstrate this goes as follows:
>>> import io
>>> from juliacall import Main as jl
>>> s = "a\nb\nc\n" # test string representing multi-line file
>>> with io.StringIO(s) as i:
... jl.readline(i)
... jl.readline(i)
... jl.readline(i)
...
'a'
''
''
I would have expected to get the second and third lines as well, but they are empty strings.
If I do the same on the Python side, I get the behavior I would expect
>>> with io.StringIO(s) as i:
... i.readline()
... i.readline()
... i.readline()
...
'a\n'
'b\n'
'c\n'
I also get the behavior I would expect if I do it all on the Julia side
>>> ss = jl.IOBuffer(s)
>>> jl.readline(ss)
'a'
>>> jl.readline(ss)
'b'
>>> jl.readline(ss)
'c'
It's not clear to me where the problem begins, but the net effect is that in my application I cannot pass a StringIO object from Python to a parser written in Julia and the obvious workaround is to pass an IOBuffer instead.
I also tested on Python v3.10.8 and got the same results
Hello, I am using Julia v1.8.5, Python v3.11.2, and
juliacallv0.9.12. I am linking a Julia package to a Python web app and running into some issues with interoperability ofStringIOobjects. A MWE to demonstrate this goes as follows:I would have expected to get the second and third lines as well, but they are empty strings.
If I do the same on the Python side, I get the behavior I would expect
I also get the behavior I would expect if I do it all on the Julia side
It's not clear to me where the problem begins, but the net effect is that in my application I cannot pass a
StringIOobject from Python to a parser written in Julia and the obvious workaround is to pass anIOBufferinstead.I also tested on Python v3.10.8 and got the same results