Browse Source

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/cli.py", line 99, in main
        options = process_args()
      File "/home/zorun/tmp/himport/himport/cli.py", line 44, in process_args
        print(usage)
      File "/usr/lib/python3.7/codecs.py", line 378, in write
        self.stream.write(data)
    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
characters.
Baptiste Jonglez 6 years ago
parent
commit
568de8accd
1 changed files with 2 additions and 4 deletions
  1. 2 4
      himport/cli.py

+ 2 - 4
himport/cli.py

@@ -16,12 +16,10 @@ from himport.dolibarrAlchemyHledger import HledgerDolibarrSQLAlchemy
 logging.basicConfig(level=logging.INFO)
 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> ] ...
         options:
             -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'])