Showing posts with label files. Show all posts
Showing posts with label files. Show all posts

04 May 2011

What is an "application/octet-stream" MIME attachment

A MIME attachment with the content type "application/octet-stream" is a binary file. Typically, it will be an application or a document that must be opened in an application, such as a spreadsheet or word processor.

No matter what kind of file it is, an application/octet-stream attachment is rarely viewable in an email, Usenet, or web client.

In addition to the generic application/octet-stream content type, you may also encounter attachments that have different subtypes (e.g., application/postscript, application/x-macbinary, and application-msword). They are similar to application/octet-stream, but apply to specific kinds of files.

28 August 2010

Python file hack


  # Echo the contents of a file
  f = open('foo.txt', 'rU')
  for line in f:   ## iterates over the lines of the file
    print line,    ## trailing , so print does not add an end-of-line char
                   ## since 'line' already includes the end-of line.
  f.close()

The special mode 'rU' is the "Universal" option for text files where it's smart about converting different line-endings so they always come through as a simple '\n'. This is a really useful hack about reading files that have heterogeneous line formats!