Sugar.mime: Difference between revisions
Jump to navigation
Jump to search
(New page: = Helper Functions = === Given a specific filename, how do I figure out what its mime type is? === The mime.get_from_file_name() method lets you get the mime type based on the name of a g...) |
|||
Line 1: | Line 1: | ||
= Helper Functions = |
= Helper Functions = |
||
=== Given a specific |
=== Given a specific file, how do I figure out what its mime type is? === |
||
The mime.get_from_file_name() method lets you get the mime type based on the name of a given file. |
The mime.get_from_file_name() method lets you get the mime type based on the name of a given file. The mime.get_for_file() is a little more robust and can get mime types often without an extension. |
||
<pre> |
<pre> |
||
Line 9: | Line 9: | ||
# Get the mime type for a specific file |
# Get the mime type for a specific file |
||
print mime.get_from_file_name('~/file-test/sample-music.mp3') |
print mime.get_from_file_name('~/file-test/sample-music.mp3') |
||
# Get mime type for a file (does some more sophisticated checking on the file - not |
|||
# dependent upon the file extension). |
|||
print mime.get_for_file('/home/fanwar/file-test/sample-acrobat') |
|||
</pre> |
</pre> |
||
Revision as of 21:07, 1 July 2008
Helper Functions
Given a specific file, how do I figure out what its mime type is?
The mime.get_from_file_name() method lets you get the mime type based on the name of a given file. The mime.get_for_file() is a little more robust and can get mime types often without an extension.
from sugar import mime ... # Get the mime type for a specific file print mime.get_from_file_name('~/file-test/sample-music.mp3') # Get mime type for a file (does some more sophisticated checking on the file - not # dependent upon the file extension). print mime.get_for_file('/home/fanwar/file-test/sample-acrobat')