Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80916

Re: How to fix those errors?

References <CAA+hu4UHArORYeNjcF5bsEEG7V64+V8abrXozGXP9GqPyR8P2Q@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2014-11-16 14:59 -0700
Subject Re: How to fix those errors?
Newsgroups comp.lang.python
Message-ID <mailman.15912.1416175191.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Nov 16, 2014 at 2:32 PM, Abdul Abdul <abdul.sw84@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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How to fix those errors? Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-16 14:59 -0700

csiph-web