def can_init():
 if (not sys.stdout.isatty()):
  return False
 if sys.flags.interactive:
  return False
 mods = sys.modules.keys()
 for repl in ['IPython', 'bpython', 'dreampielib']:
  if (repl in mods):
   return False
 try:
  raise BaseException
 except BaseException:
  frame = sys.exc_info()[2].tb_frame
 while frame:
  if (frame.f_code.co_filename == '<stdin>'):
   return False
  frame = frame.f_back
 return True

def can_init ( ) : if ( not sys . stdout . isatty ( ) ) : return False if sys . flags . interactive : return False mods = sys . modules . keys ( ) for repl in [ 'IPython' , 'bpython' , 'dreampielib' ] : if ( repl in mods ) : return False try : raise BaseException except BaseException : frame = sys . exc_info ( ) [ 2 ] . tb_frame while frame : if ( frame . f_code . co_filename == '<stdin>' ) : return False frame = frame . f_back return True
this function returns true iff stderr is a tty and we are not inside a repl .