Fix fix_print
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# ------------------------------------------------------------------------------------------------
+from __future__ import print_function
import MalmoPython
import os
import sys
import errno
def fix_print():
+ # We want to flush the print output immediately, so that we can view test output as it happens.
+ # The way to do this changed completely between Python 2 and 3, with the result that setting this
+ # in a cross-compatible way requires a few lines of ugly code.
+ # Rather than include this mess in every single sample, it's nice to wrap it into a handy
+ # function - hence this.
if sys.version_info[0] == 2:
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) # flush print output immediately
else:
import functools
- global print
- print = functools.partial(print, flush=True)
+ # Have to assign to builtins or the change won't make it outside of this module's scope
+ import builtins
+ builtins.print = functools.partial(print, flush=True)
def parse_command_line(agent_host):
# Add standard options required by test suite:
@@ -50,6 +57,9 @@ def get_video_xml(agent_host):
return '<VideoProducer><Width>860</Width><Height>480</Height></VideoProducer>' if agent_host.receivedArgument("record_video") else ''
def get_default_recording_object(agent_host, filename):
+ # Convenience method for setting up a recording object - assuming the recording_dir and record_video
+ # flags were passed in as command line arguments (see parse_command_line above).
+ # (If no recording destination was passed in, we assume no recording is required.)
my_mission_record = MalmoPython.MissionRecordSpec()
recordingsDirectory = get_recordings_directory(agent_host)
if recordingsDirectory:
