Commit 568de8ac authored by Baptiste Jonglez's avatar Baptiste Jonglez
Browse files

Don't override sys.stdout

This caused Python3 (3.7.2 to be precise) to fail to print to stdout:

    Traceback (most recent call last):
      File "/home/zorun/.local/bin/himport", line 11, in <module>
        load_entry_point('himport', 'console_scripts', 'himport')()
      File "/home/zorun/tmp/himport/himport/", line 99, in main
        options = process_args()
      File "/home/zorun/tmp/himport/himport/", line 44, in process_args
      File "/usr/lib/python3.7/", line 378, in write
    TypeError: write() argument must be str, not bytes

After removing the sys.stdout redefinition, python3 is now happy, and
python2 seems to still be able to print to stdout even with unicode
parent 2055f54a
......@@ -16,12 +16,10 @@ from himport.dolibarrAlchemyHledger import HledgerDolibarrSQLAlchemy
logger = logging.getLogger('hreport')
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
def process_args():
options = {}
usage = u'''Usage: himport -v -y <YEAR> [ -y <YEAR> ] ...
usage = '''Usage: himport -v -y <YEAR> [ -y <YEAR> ] ...
-v : verbose mode
-y <YEAR> : import the corresponding accounting year
......@@ -82,7 +80,7 @@ def do_sqlalchemy(options):
if len(pc_missing) > 0:
print("WARNING: poste comptable manquant")
for pc in pc_missing:
sys.stdout.write("%s\n" % (pc))
print("%s" % (pc))
# On ecrie les fichiers hledger
Writer.write("bank", bank_journal, options['years'])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment