Make update_version.py compatible with Python 3 (#8555)

diff --git a/update_version.py b/update_version.py
index 470e425..cb5ab98 100755
--- a/update_version.py
+++ b/update_version.py
@@ -13,25 +13,25 @@
 from xml.dom import minidom
 
 if len(sys.argv) < 2 or len(sys.argv) > 3:
-  print """
+  print("""
 [ERROR] Please specify a version.
 
 ./update_version.py <MAJOR>.<MINOR>.<MICRO> [<RC version>]
 
 Example:
 ./update_version.py 3.7.1 2
-"""
+""")
   exit(1)
 
 NEW_VERSION = sys.argv[1]
 NEW_VERSION_INFO = [int(x) for x in NEW_VERSION.split('.')]
 if len(NEW_VERSION_INFO) != 3:
-  print """
+  print("""
 [ERROR] Version must be in the format <MAJOR>.<MINOR>.<MICRO>
 
 Example:
 ./update_version.py 3.7.3
-"""
+""")
   exit(1)
 
 RC_VERSION = -1
@@ -71,9 +71,9 @@
   content = document.toxml().replace('<?xml version="1.0" ?>', '')
   file_handle = open(filename, 'wb')
   if add_xml_prefix:
-    file_handle.write('<?xml version="1.0" encoding="UTF-8"?>\n')
-  file_handle.write(content)
-  file_handle.write('\n')
+    file_handle.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
+  file_handle.write(content.encode('utf-8'))
+  file_handle.write(b'\n')
   file_handle.close()
 
 
@@ -83,7 +83,7 @@
   for line in lines:
     updated_lines.append(line_rewriter(line))
   if lines == updated_lines:
-    print '%s was not updated. Please double check.' % filename
+    print('%s was not updated. Please double check.' % filename)
   f = open(filename, 'w')
   f.write(''.join(updated_lines))
   f.close()
@@ -245,11 +245,11 @@
   protobuf_version_offset = 11
   expected_major_version = 3
   if NEW_VERSION_INFO[0] != expected_major_version:
-    print """[ERROR] Major protobuf version has changed. Please update
+    print("""[ERROR] Major protobuf version has changed. Please update
 update_version.py to readjust the protobuf_version_offset and
 expected_major_version such that the PROTOBUF_VERSION in src/Makefile.am is
 always increasing.
-    """
+    """)
     exit(1)
 
   protobuf_version_info = '%d:%d:0' % (