diff --git a/sphinx_gallery/gen_rst.py b/sphinx_gallery/gen_rst.py
index 64c2047..ed04ba2 100644
--- a/sphinx_gallery/gen_rst.py
+++ b/sphinx_gallery/gen_rst.py
@@ -508,7 +508,7 @@ def execute_code_block(compiler, block, example_globals,
         os.chdir(cwd)
 
         captured_std = captured_std.getvalue().expandtabs()
-        if captured_std:
+        if captured_std and not captured_std.isspace():
             captured_std = CODE_OUTPUT.format(indent(captured_std, u' ' * 4))
         else:
             captured_std = ''

diff --git a/sphinx_gallery/tests/test_gen_rst.py b/sphinx_gallery/tests/test_gen_rst.py
index 82644ad..2442540 100644
--- a/sphinx_gallery/tests/test_gen_rst.py
+++ b/sphinx_gallery/tests/test_gen_rst.py
@@ -448,6 +448,27 @@ def test_output_indentation(gallery_conf):
     assert output_test_string == test_string.replace(r"\n", "\n")
 
 
+def test_empty_output_box(gallery_conf):
+    """Tests that `print(__doc__)` doesn't produce an empty output box."""
+    compiler = codeop.Compile()
+    
+    code_block = ("code", "print(__doc__)", 1)
+
+    script_vars = {
+        "execute_script": True,
+        "image_path_iterator": ImagePathIterator("temp.png"),
+        "src_file": __file__,
+        "memory_delta": [],
+    }
+
+    example_globals = {'__doc__': ''}
+
+    output = sg.execute_code_block(
+        compiler, code_block, example_globals, script_vars, gallery_conf
+    )
+    assert output.isspace() == True
+
+
 class TestLoggingTee:
     def setup(self):
         self.output_file = io.StringIO()

Small regression in 0.4.1: print(__doc__) creates empty output block 
Seen in https://github.com/scikit-learn/scikit-learn/pull/14507#issuecomment-516466110, `print(__doc__)` creates empty output box (yellowish box in the output below). 

![image](https://user-images.githubusercontent.com/1680079/62141734-5f74e380-b2ed-11e9-9796-4ff96ae33d63.png)

This was introduced by https://github.com/sphinx-gallery/sphinx-gallery/pull/475. A simple fix would be to not have an output box if `my_stdout.isspace()` and add a test similar to the one introduced in #475 to check that `print(__doc__)` does not create an output box.

Small reminder: many scikit-learn examples have `print(__doc__)` at the beginning, so inside sphinx-gallery we set `__doc__ = ''` (`__doc__` is already rendered at the top of the example HTML so you don't want it captured in stdout as well).

ping @lucyleeow who is interested to work on this.

sphinx_gallery/tests/test_gen_rst.py::test_empty_output_box
sphinx_gallery/tests/test_gen_rst.py::test_split_code_and_text_blocks sphinx_gallery/tests/test_gen_rst.py::test_bug_cases_of_notebook_syntax sphinx_gallery/tests/test_gen_rst.py::test_direct_comment_after_docstring sphinx_gallery/tests/test_gen_rst.py::test_rst_block_after_docstring sphinx_gallery/tests/test_gen_rst.py::test_script_vars_globals sphinx_gallery/tests/test_gen_rst.py::test_codestr2rst sphinx_gallery/tests/test_gen_rst.py::test_extract_intro_and_title sphinx_gallery/tests/test_gen_rst.py::test_md5sums sphinx_gallery/tests/test_gen_rst.py::test_fail_example sphinx_gallery/tests/test_gen_rst.py::test_remove_config_comments sphinx_gallery/tests/test_gen_rst.py::test_gen_dir_rst[.txt] sphinx_gallery/tests/test_gen_rst.py::test_gen_dir_rst[.rst] sphinx_gallery/tests/test_gen_rst.py::test_gen_dir_rst[.bad] sphinx_gallery/tests/test_gen_rst.py::test_pattern_matching sphinx_gallery/tests/test_gen_rst.py::test_thumbnail_number[# sphinx_gallery/tests/test_gen_rst.py::test_thumbnail_number[#sphinx_gallery_thumbnail_number sphinx_gallery/tests/test_gen_rst.py::test_thumbnail_number[ sphinx_gallery/tests/test_gen_rst.py::test_zip_notebooks sphinx_gallery/tests/test_gen_rst.py::test_rst_example sphinx_gallery/tests/test_gen_rst.py::test_output_indentation