code: def is_file(obj):
      
      return all(
          [callable(getattr(obj, method_name, None)) for method_name in ('__enter__', '__exit__')]
          +
          [any([callable(getattr(obj, method_name, None)) for method_name in ('next', '__iter__')])]
      )
docs: Retrun True is object has 'next', '__enter__' and '__exit__' methods.
  
      Suitable to check both builtin ``file`` and ``django.core.file.File`` instances.