Skip to content

Commit

Permalink
Merge pull request #121 from manics/stdout
Browse files Browse the repository at this point in the history
Ensure stdout works in Jupyter Notebooks
  • Loading branch information
sbesson committed Aug 20, 2020
2 parents aa1457d + ad3c924 commit 1d0d6ee
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions ome_model/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
import uuid
import xml.etree.ElementTree as ET

if sys.version_info[0] > 2:
PYTHON = 3
else:
PYTHON = 2

OME_ATTRIBUTES = {
'Creator': "ome_model/experimental.py",
'UUID': "urn:uuid:%s" % uuid.uuid4(),
Expand Down Expand Up @@ -235,12 +230,14 @@ def create_companion(plates=[], images=[], out=None):

# https://stackoverflow.com/a/48671499/56887
kwargs = dict(encoding="UTF-8")
if PYTHON >= 3:
kwargs["xml_declaration"] = True
if not out:
kwargs["xml_declaration"] = True
if not out:
try:
out = sys.stdout.buffer
elif not out:
out = sys.stdout
except AttributeError:
# ipykernel.iostream.OutStream (used by Jupyter Notebook) does not
# have a .buffer attribute
out = sys.stdout
ET.ElementTree(root).write(out, **kwargs)


Expand Down

0 comments on commit 1d0d6ee

Please sign in to comment.