file.write() need bytes when file is opened in binary mode
diff --git a/bindings/const_generator.py b/bindings/const_generator.py
index 0b97622..1ed303f 100644
--- a/bindings/const_generator.py
+++ b/bindings/const_generator.py
@@ -66,11 +66,12 @@
 
 def gen(lang):
     global include, INCL_DIR
+    print('Generating bindings for', lang)
     templ = template[lang]
     for target in include:
         prefix = templ[target]
-        outfile = open(templ['out_file'] %(prefix), 'w')
-        outfile.write(templ['header'] % (prefix))
+        outfile = open(templ['out_file'] %(prefix), 'wb')   # open as binary prevents windows newlines
+        outfile.write((templ['header'] % (prefix)).encode("utf-8"))
 
         lines = open(INCL_DIR + target).readlines()
 
@@ -79,8 +80,9 @@
             line = line.strip()
 
             if line.startswith(MARKUP):  # markup for comments
-                outfile.write("\n%s%s%s\n" %(templ['comment_open'], \
-                            line.replace(MARKUP, ''), templ['comment_close']))
+                outfile.write(("\n%s%s%s\n" %(templ['comment_open'], \
+                                              line.replace(MARKUP, ''), \
+                                              templ['comment_close']) ).encode("utf-8"))
                 continue
 
             if line == '' or line.startswith('//'):
@@ -108,7 +110,7 @@
                     try:
                         count = int(rhs) + 1
                         if (count == 1):
-                            outfile.write("\n")
+                            outfile.write(("\n").encode("utf-8"))
                     except ValueError:
                         if lang == 'ocaml':
                             # ocaml uses lsl for '<<', lor for '|'
@@ -118,9 +120,9 @@
                             if rhs[0].isalpha():
                                 rhs = '_' + rhs
 
-                    outfile.write(templ['line_format'] %(f[0].strip(), rhs))
+                    outfile.write((templ['line_format'] %(f[0].strip(), rhs)).encode("utf-8"))
 
-        outfile.write(templ['footer'])
+        outfile.write((templ['footer']).encode("utf-8"))
         outfile.close()
 
 def main():