@@ -269,7 +269,7 @@ def add_np_implementation(function, docstring):
269269
270270
271271def read_file (path ):
272- with open (path ) as f :
272+ with open (path , encoding = 'utf-8' ) as f :
273273 return f .read ()
274274
275275
@@ -326,7 +326,7 @@ def get_module_docstring(filepath):
326326
327327 Also finds the line at which the docstring ends.
328328 """
329- co = compile (open (filepath ).read (), filepath , 'exec' )
329+ co = compile (open (filepath , encoding = 'utf-8' ).read (), filepath , 'exec' )
330330 if co .co_consts and isinstance (co .co_consts [0 ], six .string_types ):
331331 docstring = co .co_consts [0 ]
332332 else :
@@ -347,8 +347,9 @@ def copy_examples(examples_dir, destination_dir):
347347 module_path = os .path .join (examples_dir , file )
348348 docstring , starting_line = get_module_docstring (module_path )
349349 destination_file = os .path .join (destination_dir , file [:- 2 ] + 'md' )
350- with open (destination_file , 'w+' ) as f_out , \
351- open (os .path .join (examples_dir , file ), 'r+' ) as f_in :
350+ with open (destination_file , 'w+' , encoding = 'utf-8' ) as f_out , \
351+ open (os .path .join (examples_dir , file ),
352+ 'r+' , encoding = 'utf-8' ) as f_in :
352353
353354 f_out .write (docstring + '\n \n ' )
354355
@@ -391,7 +392,7 @@ def generate(sources_dir):
391392 readme = read_file (os .path .join (str (keras_dir ), 'README.md' ))
392393 index = read_file (os .path .join (template_dir , 'index.md' ))
393394 index = index .replace ('{{autogenerated}}' , readme [readme .find ('##' ):])
394- with open (os .path .join (sources_dir , 'index.md' ), 'w' ) as f :
395+ with open (os .path .join (sources_dir , 'index.md' ), 'w' , encoding = 'utf-8' ) as f :
395396 f .write (index )
396397
397398 print ('Generating docs for Keras %s.' % keras .__version__ )
@@ -457,7 +458,7 @@ def generate(sources_dir):
457458 subdir = os .path .dirname (path )
458459 if not os .path .exists (subdir ):
459460 os .makedirs (subdir )
460- with open (path , 'w' ) as f :
461+ with open (path , 'w' , encoding = 'utf-8' ) as f :
461462 f .write (mkdown )
462463
463464 shutil .copyfile (os .path .join (str (keras_dir ), 'CONTRIBUTING.md' ),
0 commit comments