Reading first line of an uploaded text file in python/django
Question: I am trying to process text files in a django app. Before I try to import the
data, I need to evaluate the first line to determine the file type.

i tried file[0], but of course that doesn't work. that did give me an error
saying its a "'InMemoryUploadedFile' object" but I can't find much
documentation about that.

So, does anyone know how to get the first line of a file?


Answer: Django's UploadedFile has a `content_type` attribute which returns MIME type
of the uploaded file supplied by user.

If you want to read the first line anyway, then you could use `readline()`
method on the uploaded file object to get the first line. As Django's
UploadedFile objects are file like objects, they support the commonly used
methods of file objects.

[Django docs on
UploadedFile](http://docs.djangoproject.com/en/dev/topics/http/file-
uploads/?from=olddocs#uploadedfile-objects)

