From 0e0d842556a7916e73bf97313affc998d851ff17 Mon Sep 17 00:00:00 2001 From: Craig Warren Date: Tue, 26 Apr 2016 17:23:38 +0100 Subject: [PATCH] Better redirection of stdout when processing Python blocks. --- gprMax/input_cmds_file.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gprMax/input_cmds_file.py b/gprMax/input_cmds_file.py index 1a83ef3b..40a564b3 100644 --- a/gprMax/input_cmds_file.py +++ b/gprMax/input_cmds_file.py @@ -45,6 +45,9 @@ def process_python_include_code(inputfile, usernamespace): # Process any Python code if(inputlines[x].startswith('#python:')): + # Save stdout location to restore later + stdout = sys.stdout + # String to hold Python code to be executed pythoncode = '' x += 1 @@ -67,6 +70,9 @@ def process_python_include_code(inputfile, usernamespace): # Add processed Python code to list processedlines.extend(codeproc) + # Reset stdio + sys.stdout = stdout + # Process any include commands elif(inputlines[x].startswith('#include:')): includefile = inputlines[x].split() @@ -94,8 +100,6 @@ def process_python_include_code(inputfile, usernamespace): processedlines.append(inputlines[x]) x += 1 - - sys.stdout = sys.__stdout__ # Reset stdio return processedlines