How to fix those errors?

Ian Kelly ian.g.kelly at gmail.com
Sun Nov 16 22:59:00 CET 2014


On Sun, Nov 16, 2014 at 2:32 PM, Abdul Abdul <abdul.sw84 at gmail.com> wrote:
> Hello,
>
> I'm walking through an example that goes as follows:
>
> from PIL import Image
> import os
>
>     for inputfile in filelist
>     outputfile = os.path.splitext(inputfile)[0]+".jpg"
>     if inputfile != outputfile:
>         try:
>             Image.open(inputfile).save(outputfile)
>             except IOError:
>             print "unable to convert ", inputfile
>
> I'm writing that in "Pycharm", and getting the following errors:
>
> * filelist ---> Unresolved reference 'filelist'

Your for loop iterates over a variable called filelist, but you never define it.

> * IOError: Statement seems to have no effect
>
> * The last 'filelist' ---> 'except' or 'finally' expected

The indentation of your try and except statements don't appear to
match, which is probably confusing it. The except should be at the
same indentation level as the try. Also, the for should presumably be
at the same indentation level as the imports, as it's not contained
within a block.



More information about the Python-list mailing list