modified python solution to print to stdout by default if output file is not specified