From 4ae452c68177ee1beed7145547b776e91ca42a84 Mon Sep 17 00:00:00 2001 From: stephanobryan Date: Mon, 3 Jun 2019 18:36:41 +0200 Subject: [PATCH] Update __init__.py Hi @jpsenior , Thanks for the great package :-). Though I have a little input: I'd substitut lines 77-78 in the old _init_.py with lines 77-85, so that it is Python 3 compatible. Cheers.. --- sphinx_execute_code/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sphinx_execute_code/__init__.py b/sphinx_execute_code/__init__.py index 9925521..4e9e2e7 100644 --- a/sphinx_execute_code/__init__.py +++ b/sphinx_execute_code/__init__.py @@ -74,8 +74,15 @@ def execute_code(cls, code): 'foobar' """ - output = StringIO.StringIO() - err = StringIO.StringIO() + # Added by @stephanobryan for python 3 + if sys.version_info.major == 2: + from StringIO import StringIO + output = StringIO.StringIO() + err = StringIO.StringIO() + else: + import io + output = io.StringIO() + err = io.StringIO() sys.stdout = output sys.stderr = err