Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 19b1a05

Browse files
committed
Make gen_rst behave with py3
1 parent df93eca commit 19b1a05

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

doc/sphinxext/gen_rst.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
generate the rst files for the examples by iterating over the pylab examples
33
"""
44
from __future__ import print_function
5+
import io
56
import os, glob
67

78
import os
@@ -37,15 +38,15 @@ def generate_example_rst(app):
3738
continue
3839

3940
fullpath = os.path.join(root,fname)
40-
contents = file(fullpath).read()
41+
contents = io.open(fullpath, encoding='utf8').read()
4142
# indent
4243
relpath = os.path.split(root)[-1]
4344
datad.setdefault(relpath, []).append((fullpath, fname, contents))
4445

45-
subdirs = datad.keys()
46+
subdirs = list(datad.keys())
4647
subdirs.sort()
4748

48-
fhindex = file(os.path.join(exampledir, 'index.rst'), 'w')
49+
fhindex = open(os.path.join(exampledir, 'index.rst'), 'w')
4950
fhindex.write("""\
5051
.. _examples-index:
5152
@@ -77,7 +78,7 @@ def generate_example_rst(app):
7778
os.makedirs(outputdir)
7879

7980
subdirIndexFile = os.path.join(rstdir, 'index.rst')
80-
fhsubdirIndex = file(subdirIndexFile, 'w')
81+
fhsubdirIndex = open(subdirIndexFile, 'w')
8182
fhindex.write(' %s/index.rst\n\n'%subdir)
8283

8384
fhsubdirIndex.write("""\
@@ -122,14 +123,14 @@ def generate_example_rst(app):
122123
) and
123124
not noplot_regex.search(contents))
124125
if not do_plot:
125-
fhstatic = file(outputfile, 'w')
126+
fhstatic = open(outputfile, 'w')
126127
fhstatic.write(contents)
127128
fhstatic.close()
128129

129130
if not out_of_date(fullpath, outrstfile):
130131
continue
131132

132-
fh = file(outrstfile, 'w')
133+
fh = io.open(outrstfile, 'w', encoding='utf8')
133134
fh.write('.. _%s-%s:\n\n'%(subdir, basename))
134135
title = '%s example code: %s'%(subdir, fname)
135136
#title = '<img src=%s> %s example code: %s'%(thumbfile, subdir, fname)

0 commit comments

Comments
 (0)