[pygtk] Working with files with python (gtk)

Benjamin Sergeant bsergean at gmail.com
Fri Mar 16 07:42:38 WST 2007


I'm affraid mimetypes cannot help.

[bsergean at marge1 mime]$ cp /media/photos/Pooky/IMG_0754.JPG .
[bsergean at marge1 mime]$ cp /media/photos/Pooky/IMG_0754.JPG foo.txt
[bsergean at marge1 mime]$ python
Python 2.4.3 (#2, Oct  6 2006, 15:32:41)
[GCC 4.1.1 20060724 (prerelease) (4.1.1-3mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mimetypes
>>> mimetypes.guess_type('IMG_0754.JPG')
('image/jpeg', None)
>>> mimetypes.guess_type('foo.txt')
('text/plain', None)

The unix file command might help thought:

[bsergean at marge1 mime]$ file foo.txt
foo.txt: JPEG image data, EXIF standard 2.2


Benjamin.

On 3/15/07, Edward A Robinson <earobinson at gmail.com> wrote:
> This is my first time posting to the python tutor so be nice, I have
> read the mailing list and cant seem to find and answer there or on
> google so I turn to you guys for help. I'm working on a gtk
> application and I want to list all the image files in a directory. Now
> I know that if I have an image lets say foo.png and I rename that to
> foo.txt nautilus (the default gnome browser) still recognizes that
> file as an image.How can I do the same thing?
>
> I guess what Im looking for is a python command that dose what the
> file command in the shell would do, as well as figure out the correct
> program to open the file with.
>
> As well as recognizes images I want users to be able to open up each
> image with that images default editor. So foo.png may open with eye of
> gnome but bar.jpg may open with gimp. (If those where the settings in
> nautilus)
>
> Also how would I get cut and paste to work so that I can cut a file
> from my image browser then paste it into nautilus. I know how to get
> it to work for basic text but not for files.
>
> Thanks for your time, I hope this is an appropriate query for this mailing list.
>
> --
> Edward A Robinson
> _______________________________________________
> pygtk mailing list   pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
>


More information about the pygtk mailing list