Mercurial > p > roundup > code
diff roundup/msgfmt.py @ 5376:64b05e24dbd8
Python 3 preparation: convert print to a function.
Tool-assisted patch. It is possible that some "from __future__ import
print_function" are not in fact needed, if a file only uses print()
with a single string as an argument and so would work fine in Python 2
without that import.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Tue, 24 Jul 2018 09:54:52 +0000 |
| parents | 198b6e810c67 |
| children | 64c4e43fbb84 |
line wrap: on
line diff
--- a/roundup/msgfmt.py Sat Jul 21 23:07:16 2018 +1000 +++ b/roundup/msgfmt.py Tue Jul 24 09:54:52 2018 +0000 @@ -26,6 +26,7 @@ Display version information and exit. """ +from __future__ import print_function import sys import os import getopt @@ -39,9 +40,9 @@ def usage(code, msg=''): - print >> sys.stderr, __doc__ + print(__doc__, file=sys.stderr) if msg: - print >> sys.stderr, msg + print(msg, file=sys.stderr) sys.exit(code) @@ -117,7 +118,7 @@ try: lines = open(infile).readlines() except IOError as msg: - print >> sys.stderr, msg + print(msg, file=sys.stderr) sys.exit(1) # remove UTF-8 Byte Order Mark, if any. @@ -176,9 +177,9 @@ elif section == STR: msgstr += l else: - print >> sys.stderr, 'Syntax error on %s:%d' % (infile, lno), \ - 'before:' - print >> sys.stderr, l + print('Syntax error on %s:%d' % (infile, lno), + 'before:', file=sys.stderr) + print(l, file=sys.stderr) sys.exit(1) # Add last entry if section == STR: @@ -190,7 +191,7 @@ try: open(outfile,"wb").write(output) except IOError as msg: - print >> sys.stderr, msg + print(msg, file=sys.stderr) @@ -207,14 +208,14 @@ if opt in ('-h', '--help'): usage(0) elif opt in ('-V', '--version'): - print >> sys.stderr, "msgfmt.py", __version__ + print("msgfmt.py", __version__, file=sys.stderr) sys.exit(0) elif opt in ('-o', '--output-file'): outfile = arg # do it if not args: - print >> sys.stderr, 'No input file given' - print >> sys.stderr, "Try `msgfmt --help' for more information." + print('No input file given', file=sys.stderr) + print("Try `msgfmt --help' for more information.", file=sys.stderr) return for filename in args:
