[Tutor] subprocess.call

davidwilson at Safe-mail.net davidwilson at Safe-mail.net
Mon Jul 27 19:16:26 CEST 2009


Hello again,
>From my previous post I would now like to transform the SVG images using the svg2png library, but am having difficulties in making it work. Here is the code:

import glob
import csv
from os import rename
import subprocess

countries = {}
reader = csv.reader(open("countries.csv"))
for row in reader:
    code, name = row
    countries[name] = code

files = set([file for file in glob.glob('Flag_of_*.svg')])

for filename in files:
    fn = filename[8:-4]
    if fn.startswith('the_'):
	fn = fn[4:]
    if fn in countries:
	new_filename = 'flag-%s' % countries[fn]

    subprocess.call(['svg2png --width=17 --height=12 %s %s' \
    		% (filename, new_filename  + '.png')])

$ python rename_svg.py 
Traceback (most recent call last):
  File "rename_svg.py", line 22, in <module>
    % (filename, new_filename  + '.png')])
  File "/home/dwilson/usr/local/python2.6/lib/python2.6/subprocess.py", line 444, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/home/dwilson/usr/local/python2.6/lib/python2.6/subprocess.py", line 595, in __init__
    errread, errwrite)
  File "/home/dwilson/usr/local/python2.6/lib/python2.6/subprocess.py", line 1092, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Where am I doing this wrong?

Dave


More information about the Tutor mailing list