import os
import sys
import builtins

def open(file, mode=None, encoding=None):
  if mode == None: mode = 'r'

  if '/' in file:
    if 'w' or 'a' in mode:
      dir = os.path.dirname(file)
      if not os.path.isdir(dir):  os.makedirs(dir)

  f = builtins.open(file, mode=mode, encoding=encoding)
  return f

# http://stackoverflow.com/questions/34950201/pycharm-print-end-r-statement-not-working
class Logger(object):
  def __init__(self):
    self.terminal = sys.stdout  #stdout
    self.file = None

  def open(self, file, mode=None):
    if mode is None: mode ='w'
    self.file = open(file, mode)

  def write(self, message, is_terminal=1, is_file=1 ):
    if '\r' in message: is_file=0

    if is_terminal == 1:
      self.terminal.write(message)
      self.terminal.flush()
      #time.sleep(1)

    if is_file == 1:
      self.file.write(message)
      self.file.flush()

  def flush(self):
    # this flush method is needed for python 3 compatibility.
    # this handles the flush command by doing nothing.
    # you might want to specify some extra behavior here.
    pass

import os
import sys
import builtins

def open(file, mode=None, encoding=None):
  if mode == None: mode = 'r'

  if '/' in file:
    if 'w' or 'a' in mode:
      dir = os.path.dirname(file)
      if not os.path.isdir(dir):  os.makedirs(dir)

  f = builtins.open(file, mode=mode, encoding=encoding)
  return f

# http://stackoverflow.com/questions/34950201/pycharm-print-end-r-statement-not-working
class Logger(object):
  def __init__(self):
    self.terminal = sys.stdout  #stdout
    self.file = None

  def open(self, file, mode=None):
    if mode is None: mode ='w'
    self.file = open(file, mode)

  def write(self, message, is_terminal=1, is_file=1 ):
    if '\r' in message: is_file=0

    if is_terminal == 1:
      self.terminal.write(message)
      self.terminal.flush()
      #time.sleep(1)

    if is_file == 1:
      self.file.write(message)
      self.file.flush()

  def flush(self):
    # this flush method is needed for python 3 compatibility.
    # this handles the flush command by doing nothing.
    # you might want to specify some extra behavior here.
    pass

# http://stackoverflow.com/questions/34950201/pycharm-print-end-r-statement-not-working #stdout #time.sleep(1) # this flush method is needed for python 3 compatibility. # this handles the flush command by doing nothing. # you might want to specify some extra behavior here.