dopefishh / pympi

A python module for processing ELAN and Praat annotation files
MIT License
93 stars 39 forks source link

Writing an eaf object to stdout doesn't work in python 3 #10

Closed IgorBMSTU closed 7 years ago

IgorBMSTU commented 7 years ago

example:

igor@bgmlv ~/git_projects/pympi $ cat stdout_test.py

import pympi
elan_obj = pympi.Elan.Eaf()
elan_obj.to_file("-")

igor@bgmlv ~/git_projects/pympi $ . env_py2/bin/activate (env_py2) igor@bgmlv ~/git_projects/pympi $ python stdout_test.py

<?xml version='1.0' encoding='UTF-8'?>
<ANNOTATION_DOCUMENT AUTHOR="pympi" DATE="2016-12-08T13:26:51-05:00" FORMAT="2.8" VERSION="2.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.mpi.nl/tools/elan/EAFv2.8.xsd">
    <HEADER>
        <PROPERTY NAME="lastUsedAnnotation">0</PROPERTY>
        </HEADER>
    <TIME_ORDER />
    <TIER LINGUISTIC_TYPE_REF="default-lt" TIER_ID="default" />
    <LINGUISTIC_TYPE GRAPHIC_REFERENCES="false" LINGUISTIC_TYPE_ID="default-lt" TIME_ALIGNABLE="true" />
    <CONSTRAINT DESCRIPTION="Time subdivision of parent annotation's time interval, no time gaps allowed within this interval" STEREOTYPE="Time_Subdivision" />
    <CONSTRAINT DESCRIPTION="Symbolic subdivision of a parent annotation. Annotations refering to the same parent are ordered" STEREOTYPE="Symbolic_Subdivision" />
    <CONSTRAINT DESCRIPTION="1-1 association with a parent annotation" STEREOTYPE="Symbolic_Association" />
    <CONSTRAINT DESCRIPTION="Time alignable annotations within the parent annotation's time interval, gaps are allowed" STEREOTYPE="Included_In" />
    </ANNOTATION_DOCUMENT>

(env_py2) igor@bgmlv ~/git_projects/pympi $ deactivate igor@bgmlv ~/git_projects/pympi $ . env_py3/bin/activate (env_py3) igor@bgmlv ~/git_projects/pympi $ python stdout_test.py

Traceback (most recent call last):
  File "stdout_test.py", line 3, in <module>
    elan_obj.to_file("-")
  File "/home/igor/git_projects/pympi/env_py3/lib/python3.4/site-packages/pympi/Elan.py", line 1315, in to_file
    to_eaf(file_path, self, pretty)
  File "/home/igor/git_projects/pympi/env_py3/lib/python3.4/site-packages/pympi/Elan.py", line 1688, in to_eaf
    file_path, xml_declaration=True, encoding='UTF-8')
  File "/usr/lib/python3.4/xml/etree/ElementTree.py", line 778, in write
    short_empty_elements=short_empty_elements)
  File "/usr/lib/python3.4/contextlib.py", line 66, in __exit__
    next(self.gen)
  File "/usr/lib/python3.4/xml/etree/ElementTree.py", line 837, in _get_writer
    yield file.write
  File "/usr/lib/python3.4/contextlib.py", line 336, in __exit__
    raise exc_details[1]
  File "/usr/lib/python3.4/contextlib.py", line 321, in __exit__
    if cb(*exc_details):
  File "/usr/lib/python3.4/contextlib.py", line 267, in _exit_wrapper
    callback(*args, **kwds)
TypeError: must be str, not bytes