From 48a2db509f4c4cf8370fa34cc0a21d88a7a9e8fd Mon Sep 17 00:00:00 2001 From: Kelsey Hawley Date: Fri, 20 Dec 2013 13:47:41 -0800 Subject: [PATCH] updated string printing to be consistent between python 2 & 3. Previously, python 3 would print the db key & values as byte code, while python 2 inherently ignores this when printing. Now the stdout is the same in both versions. --- bin/dump-anydbm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bin/dump-anydbm b/bin/dump-anydbm index 83e1872..689c9ca 100755 --- a/bin/dump-anydbm +++ b/bin/dump-anydbm @@ -45,11 +45,17 @@ if __name__ == "__main__": elif which == '': sys.stderr.write("{} is an unrecognized database type\n".format(sys.argv[1])) + sys.stderr.write("Try the file again by removing the extension\n") exit(1) - print('{} is a {} db'.format(filename, which)) + try: + out = sys.stdout.buffer + + except AttributeError: + out = sys.stdout + + out.write(filename.encode('UTF-8') + b' is a ' + which.encode('UTF-8') + b' db\n') db = dbm.open(filename, 'r') - for key in db.keys(): - print("{}:{}".format(key, db[key])) + out.write(key + b":" + db[key] + b"\n")