Browse Source

fix stdout and stderr output in python2

master
OhYee 8 months ago
parent
commit
3c272eb5d6
  1. 2
      addon/json.py
  2. 2
      addon/watch.py
  3. 2
      utils/__init__.py
  4. 18
      utils/output.py

2
addon/json.py

@ -82,7 +82,7 @@ class JSON(Addon): @@ -82,7 +82,7 @@ class JSON(Addon):
print(jsonText)
except Exception as e:
stderr(e)
stderrLine(e)
print(text)
def parse(self, repl, text):

2
addon/watch.py

@ -83,7 +83,7 @@ class Watch(Addon): @@ -83,7 +83,7 @@ class Watch(Addon):
p = os.popen(cmd)
value = float(p.read())
except Exception as e:
stderr(e)
stderrLine(e)
value = 0
slice[idx].append(value)
if len(slice[idx]) > number:

2
utils/__init__.py

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
# -*- coding:utf-8 -*-
from .context import ctx
from .output import debug, stdout, stderr
from .output import debug, stdout, stderr, stdoutLine, stderrLine
from .flags import Flags, align
from .i18n import I18n
from .store import kvLoad, kvStore

18
utils/output.py

@ -9,13 +9,23 @@ def debug(*args): @@ -9,13 +9,23 @@ def debug(*args):
print(" ".join(map(str, args)))
def stdout(*args, end="\n"):
def stdout(*args):
sys.stdout.write(" ".join(map(str, args)))
sys.stdout.write(end)
sys.stdout.flush()
def stderr(*args, end="\n"):
def stdoutLine(*args):
stdout(*args)
stdout("\n")
sys.stdout.flush()
def stderr(*args):
sys.stderr.write(" ".join(map(str, args)))
sys.stderr.write(end)
sys.stderr.flush()
def stderrLine(*args):
stderr(*args)
stderr("\n")
sys.stderr.flush()

Loading…
Cancel
Save