Closed francescomambrini closed 3 years ago
It seems you have an older version of udapi. The following code works with udapi==0.2.3:
import udapi
doc = udapi.Document("sample.conllu")
print(doc.to_conllu_string())
Ooouch! I forgot to fetch a few changes to my branch... I confirm that it works as expected. Sorry for my untimely report.
I ran into the following error when I tried to use the
to_conllu_string
method of theDocument
class:What is happening is that, if we pass a io.StringIO as filehandle to a ConlluWriter (as in document.py, line 47), then the I/O object is closed in line 75 of basewriter.py:
So after that it's not possible to use
getvalue()
to get the content of the closed I/O stream.One can always use the workaround of changing the sys.output in the code, using a ConlluWriter to write to the redirected stdout, instead of passing a filehandle to the writer. That works without a problem. But I think the use case of a writer method that saves the output to a variable is an interesting and useful one. However, I am afraid I can't suggest a fix, because I wouldn't dare to touch the
BaseWriter
class.So I am just reporting the issue for the moment...