On May 31, 2007, at 8:08 PM, Sick Monkey wrote:
I ran into another slight problem. And I attempted to fix it, but
have not been able to do so yet. If a filename does not contain a
space, then this method works like a charm. But if there is a
space then the code throws a nasty error.
import os
import subprocess
from os import *
imagefile = "/somedir/images/david.huggins/Photo 1.jpg"
cmdw = "identify -format %w '"+imagefile+"'"
cmdh = "identify -format %h '"+imagefile+"'"
pw = subprocess.Popen(cmdw.split(), stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
ph = subprocess.Popen(cmdh.split(), stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
w = pw.stdout.read().strip()
h = ph.stdout.read ().strip()
------------
identify: Unable to open file ('/somedir/images/david.huggins/
Photo) [No such file or directory].
identify: Unable to open file (1.jpg') [No such file or directory].
identify: Missing an image file name [No such file or directory].
identify: Unable to open file ('/somedir/images/david.huggins/
Photo) [No such file or directory].
identify: Unable to open file (1.jpg') [No such file or directory].
identify: Missing an image file name [No such file or directory].
Traceback (most recent call last):
Try inserting a backslash before the space:
imagefile = imagefile.replace(' ', '\ ')
hth,
Michael
---
The Rules of Optimization are simple.
Rule 1: Don't do it.
Rule 2 (for experts only): Don't do it yet.
-Michael A. Jackson
--
http://mail.python.org/mailman/listinfo/python-list