1

When i run my Jupyter-notebook with python2.7 and try to print items (of a list) using a for-loop it just won't output the print statement after importing the following packages:

import sys
import os
from hachoir_core.cmd_line import unicodeFilename
from hachoir_metadata import extractMetadata
from hachoir_parser import createParser
from hachoir_core.i18n import getTerminalCharset
from hachoir_core.tools import makePrintable
import pandas as pd

example code:

items = [1, 3, 0, 4, 1]
for item in items:
   print (item)

output is blank.

When I use the exact same code before importing, it does show.

Looks like hachoir imports are the problem, whenever I import anything containing it, the output stops showing.

Thomas K
  • 39,200
  • 7
  • 84
  • 86
Daniel
  • 473
  • 4
  • 9
  • It looks like hachoir is doing something peculiar with stdout: https://bitbucket.org/haypo/fusil/issues/1/hachoir-metadata-and-ipython – Thomas K Mar 02 '16 at 13:13
  • yea it does! I tried editing the **hachoir_core_i18n.py** file as described in the link you provided; changing **'unicode(translate(text), charset)'** to **'unicode(translate(text), (charset if charset else sys.getdefaultencoding()))'** that didn't change the output of the Jupyter-notebook though – Daniel Mar 04 '16 at 12:21
  • Also, in the solution suggested the line on which the code should be changed differs from the hachoir_core_i18n.py file i have. (148 instead of 144), maybe due to an updated hachoir version – Daniel Mar 04 '16 at 12:28
  • I think you need to do the `from hachoir_core import config; config.unicode_stdout = False` step described in that link. – Thomas K Mar 04 '16 at 16:40
  • That did it! Thank you very much Thomas! – Daniel Mar 08 '16 at 10:44

1 Answers1

1

Reposting as an answer: The hachoir_metadata module appears to do something odd with stdout which breaks IPython: Bug report.

As described in that link, you need to add the following code before importing hachoir_metadata:

from hachoir_core import config
config.unicode_stdout = False
Thomas K
  • 39,200
  • 7
  • 84
  • 86