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


Groups > comp.lang.python > #80906 > unrolled thread

How to fix those errors?

Started byAbdul Abdul <abdul.sw84@gmail.com>
First post2014-11-16 22:32 +0100
Last post2014-11-19 09:33 +1100
Articles 15 — 8 participants

Back to article view | Back to comp.lang.python


Contents

  How to fix those errors? Abdul Abdul <abdul.sw84@gmail.com> - 2014-11-16 22:32 +0100
    Re: How to fix those errors? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-16 23:04 +0100
      Re: How to fix those errors? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-16 23:13 +0100
        Re: How to fix those errors? Chris Angelico <rosuav@gmail.com> - 2014-11-17 09:22 +1100
          Re: How to fix those errors? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-17 11:38 +1100
            Re: How to fix those errors? Chris Angelico <rosuav@gmail.com> - 2014-11-17 12:05 +1100
            Re: How to fix those errors? Roy Smith <roy@panix.com> - 2014-11-16 21:55 -0500
              Re: How to fix those errors? Chris Angelico <rosuav@gmail.com> - 2014-11-17 14:06 +1100
                Re: How to fix those errors? alex23 <wuwei23@gmail.com> - 2014-11-19 13:02 +1000
                  Re: How to fix those errors? Chris Angelico <rosuav@gmail.com> - 2014-11-19 14:40 +1100
                    Re: How to fix those errors? alex23 <wuwei23@gmail.com> - 2014-11-21 20:21 +1000
              Re: How to fix those errors? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-11-18 20:25 +1300
                Re: How to fix those errors? Chris Angelico <rosuav@gmail.com> - 2014-11-18 18:37 +1100
                Re: How to fix those errors? wxjmfauth@gmail.com - 2014-11-19 08:00 -0800
              Re: How to fix those errors? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-19 09:33 +1100

#80906 — How to fix those errors?

FromAbdul Abdul <abdul.sw84@gmail.com>
Date2014-11-16 22:32 +0100
SubjectHow to fix those errors?
Message-ID<mailman.15903.1416173691.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

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'

* IOError: Statement seems to have no effect

* The last 'filelist' ---> 'except' or 'finally' expected

How can I solve those errors?

Thanks.

[toc] | [next] | [standalone]


#80919

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-11-16 23:04 +0100
Message-ID<61579529.uBKFXsbbfR@PointedEars.de>
In reply to#80906
Abdul Abdul wrote:

> from PIL import Image
> import os

You should only import the methods that you use.
 
>     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
              ^^^^^^
If possible, write new programs in Python 3.x (where paretheses are required 
for print()).
 
> I'm writing that in "Pycharm",

Try PyDev or LiClipse with PyDev instead.

> and getting the following errors:
> 
> * filelist ---> Unresolved reference 'filelist'

Define “filelist” which needs to refer to an iterable value.  Also, you have 
forgotten to end the “for…in” statement with a semicolon, and you need to 
unindent it one level if it is to make sense.
 
> * IOError: Statement seems to have no effect

You have indented the “except” clause one level too many.  It must start at 
the same column as the corresponding “try” clause.  In Python, indentation 
works like block braces in C-like programming languages.  Do not mix spaces 
and tabs for indentation.
 
> * The last 'filelist' ---> 'except' or 'finally' expected

Follows from the above.  Standalone “try” clauses are not allowed.
 
> How can I solve those errors?

See above.  Summary (untested):

from PIL import Image
from os.path import splitext

filelist = ["foo", "bar"]

for inputfile in filelist:
    outputfile = splitext(inputfile)[0] + ".jpg"
    if inputfile != outputfile:
        try:
            Image.open(inputfile).save(outputfile)
        except IOError:
            print("unable to convert", inputfile)


Please do not post multi-part messages.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#80922

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-11-16 23:13 +0100
Message-ID<1692646.8RgHztCiv6@PointedEars.de>
In reply to#80919
Thomas 'PointedEars' Lahn wrote:

> Abdul Abdul wrote:
>> from PIL import Image
>> import os
> […]
>>     for inputfile in filelist
>>     outputfile = os.path.splitext(inputfile)[0]+".jpg"
>> […]
> 
> Define “filelist” which needs to refer to an iterable value.  Also, you
> have forgotten to end the “for…in” statement with a semicolon,

_colon_ (“:”)

> and you need to unindent it one level if it is to make sense.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#80925

FromChris Angelico <rosuav@gmail.com>
Date2014-11-17 09:22 +1100
Message-ID<mailman.15917.1416176562.18130.python-list@python.org>
In reply to#80922
On Mon, Nov 17, 2014 at 9:13 AM, Thomas 'PointedEars' Lahn
<PointedEars@web.de> wrote:
> Thomas 'PointedEars' Lahn wrote:
>
>> Abdul Abdul wrote:
>>> from PIL import Image
>>> import os
>> […]
>>>     for inputfile in filelist
>>>     outputfile = os.path.splitext(inputfile)[0]+".jpg"
>>> […]
>>
>> Define “filelist” which needs to refer to an iterable value.  Also, you
>> have forgotten to end the “for…in” statement with a semicolon,
>
> _colon_ (“:”)

You should be able to use two semicolons, that's equivalent to one colon right?

ChrisA
(No, it isn't, so don't take this advice. Thanks.)

[toc] | [prev] | [next] | [standalone]


#80935

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-11-17 11:38 +1100
Message-ID<54694389$0$13001$c3e8da3$5496439d@news.astraweb.com>
In reply to#80925
Chris Angelico wrote:

> You should be able to use two semicolons, that's equivalent to one colon
> right?
> 
> ChrisA
> (No, it isn't, so don't take this advice. Thanks.)


Oooh! Python-ideas territory! 

I think the parser should allow two consecutive semi-colons, or four commas,
as an alias for a colon. Then we could write code like:


def spam(arg);;
    for x in seq,,,,
        pass


for people who have a broken keyboard or have remapped colon to something
else. It would also make reading slices an exciting adventure:

    seq[1,,,,][,,,,,,,,-1]


What do you think? Is it perhaps better suited to perl-ideas?


Feeling-whimsical-at-the-moment-ly y'rs,


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#80938

FromChris Angelico <rosuav@gmail.com>
Date2014-11-17 12:05 +1100
Message-ID<mailman.15927.1416186332.18130.python-list@python.org>
In reply to#80935
On Mon, Nov 17, 2014 at 11:38 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> for people who have a broken keyboard or have remapped colon to something
> else. It would also make reading slices an exciting adventure:
>
>     seq[1,,,,][,,,,,,,,-1]
>
>
> What do you think? Is it perhaps better suited to perl-ideas?

Actually, I think this would fit in very nicely with C's trigraphs -
an excellent idea spoiled by the use of the arbitrary number three.
Using even numbers, especially powers of two, will make the idea ever
so much better.

ChrisA

[toc] | [prev] | [next] | [standalone]


#80954

FromRoy Smith <roy@panix.com>
Date2014-11-16 21:55 -0500
Message-ID<roy-45DA9A.21550716112014@news.panix.com>
In reply to#80935
In article <54694389$0$13001$c3e8da3$5496439d@news.astraweb.com>,
 Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:

> Chris Angelico wrote:
> 
> > You should be able to use two semicolons, that's equivalent to one colon
> > right?
> > 
> > ChrisA
> > (No, it isn't, so don't take this advice. Thanks.)
> 
> 
> Oooh! Python-ideas territory! 
> 
> I think the parser should allow two consecutive semi-colons, or four commas,
> as an alias for a colon. Then we could write code like:
> 
> 
> def spam(arg);;
>     for x in seq,,,,
>         pass

Wouldn't it make more sense to use four periods?

def spam(arg)....
    for x in seq....
        pass

First, 2 colons is 4 dots, so it's conservation of punctuation.  Second, 
it reads pretty well.

[toc] | [prev] | [next] | [standalone]


#80957

FromChris Angelico <rosuav@gmail.com>
Date2014-11-17 14:06 +1100
Message-ID<mailman.15943.1416193580.18130.python-list@python.org>
In reply to#80954
On Mon, Nov 17, 2014 at 1:55 PM, Roy Smith <roy@panix.com> wrote:
> Wouldn't it make more sense to use four periods?
>
> def spam(arg)....
>     for x in seq....
>         pass
>
> First, 2 colons is 4 dots, so it's conservation of punctuation.  Second,
> it reads pretty well.

You could then name it in Hebrew: Paamayim Nekudotayim. There is
excellent precedent for this - it's done by a language in whose
footsteps Python strives to follow.

ChrisA

[toc] | [prev] | [next] | [standalone]


#81023

Fromalex23 <wuwei23@gmail.com>
Date2014-11-19 13:02 +1000
Message-ID<m4h177$k3o$1@dont-email.me>
In reply to#80957
On 17/11/2014 1:06 PM, Chris Angelico wrote:
> You could then name it in Hebrew: Paamayim Nekudotayim. There is
> excellent precedent for this - it's done by a language in whose
> footsteps Python strives to follow.

The first time I got a T_PAAMAYIM_NEKUDOTAYIM error, I just about 
flipped my desk in rage.

[toc] | [prev] | [next] | [standalone]


#81025

FromChris Angelico <rosuav@gmail.com>
Date2014-11-19 14:40 +1100
Message-ID<mailman.15989.1416368415.18130.python-list@python.org>
In reply to#81023
On Wed, Nov 19, 2014 at 2:02 PM, alex23 <wuwei23@gmail.com> wrote:
> On 17/11/2014 1:06 PM, Chris Angelico wrote:
>>
>> You could then name it in Hebrew: Paamayim Nekudotayim. There is
>> excellent precedent for this - it's done by a language in whose
>> footsteps Python strives to follow.
>
>
> The first time I got a T_PAAMAYIM_NEKUDOTAYIM error, I just about flipped my
> desk in rage.

If that were Hebrew for "scope resolution operator", would it be less
rage-inducing?

ChrisA

[toc] | [prev] | [next] | [standalone]


#81189

Fromalex23 <wuwei23@gmail.com>
Date2014-11-21 20:21 +1000
Message-ID<m4n3mn$9o6$1@dont-email.me>
In reply to#81025
On 19/11/2014 1:40 PM, Chris Angelico wrote:
> On Wed, Nov 19, 2014 at 2:02 PM, alex23 <wuwei23@gmail.com> wrote:
>> The first time I got a T_PAAMAYIM_NEKUDOTAYIM error, I just about flipped my
>> desk in rage.
>
> If that were Hebrew for "scope resolution operator", would it be less
> rage-inducing?

Not especially. I prefer errors to actually use the syntax of the 
language where possible.

[toc] | [prev] | [next] | [standalone]


#80997

FromGregory Ewing <greg.ewing@canterbury.ac.nz>
Date2014-11-18 20:25 +1300
Message-ID<cd0aikF787qU1@mid.individual.net>
In reply to#80954
Roy Smith wrote:
> Wouldn't it make more sense to use four periods?
> 
> def spam(arg)....
>     for x in seq....
>         pass

Conversely, to save space you should be able to
stack one of the dots of an ellipsis on top and
write it as either .: or :.

Taking this even further, we could allow all
characters to be encoded in 90-degree-rotated
Braille. This would be a tremendous advantage
for blind or poorly-sighted Python users.

-- 
Greg

[toc] | [prev] | [next] | [standalone]


#80998

FromChris Angelico <rosuav@gmail.com>
Date2014-11-18 18:37 +1100
Message-ID<mailman.15971.1416296245.18130.python-list@python.org>
In reply to#80997
On Tue, Nov 18, 2014 at 6:25 PM, Gregory Ewing
<greg.ewing@canterbury.ac.nz> wrote:
> Taking this even further, we could allow all
> characters to be encoded in 90-degree-rotated
> Braille. This would be a tremendous advantage
> for blind or poorly-sighted Python users.

Indeed. However, which way should they be rotated? Clockwise or
counterclockwise? We would need a special encoding cookie, consisting
of the Braille encoding of "zero-width space", with a guarantee that
its inverted form will never be used to mean anything. Alternatively,
you could have programs attempt to autodetect the rotation used, which
will be perfect unless Bush hid the facts.

ChrisA

[toc] | [prev] | [next] | [standalone]


#81034

Fromwxjmfauth@gmail.com
Date2014-11-19 08:00 -0800
Message-ID<19c5c847-7ea2-4b20-ad75-ee1ced4b58d2@googlegroups.com>
In reply to#80997
Le mardi 18 novembre 2014 08:25:23 UTC+1, Gregory Ewing a écrit :
> Roy Smith wrote:
> > Wouldn't it make more sense to use four periods?
> > 
> > def spam(arg)....
> >     for x in seq....
> >         pass
> 
> Conversely, to save space you should be able to
> stack one of the dots of an ellipsis on top and
> write it as either .: or :.
> 
> Taking this even further, we could allow all
> characters to be encoded in 90-degree-rotated
> Braille. This would be a tremendous advantage
> for blind or poorly-sighted Python users.
> 
> -- 
> Greg


Unicode has a dedicated block for Braille characters
(Braille Patterns).

No need for a codec for the position and/or rotation
of characters, it's a question of rendering engine
and/or fonts.

You can experiment it with a TeX unicode engine.

--------

Sometimes, Python already allows to save space:

>>> 0and 1
0
>>> 0 and 1
0

[toc] | [prev] | [next] | [standalone]


#81017

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-11-19 09:33 +1100
Message-ID<546bc91f$0$13002$c3e8da3$5496439d@news.astraweb.com>
In reply to#80954
Roy Smith wrote:

> In article <54694389$0$13001$c3e8da3$5496439d@news.astraweb.com>,
>  Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
> 
>> Chris Angelico wrote:
>> 
>> > You should be able to use two semicolons, that's equivalent to one
>> > colon right?
>> > 
>> > ChrisA
>> > (No, it isn't, so don't take this advice. Thanks.)
>> 
>> 
>> Oooh! Python-ideas territory!
>> 
>> I think the parser should allow two consecutive semi-colons, or four
>> commas, as an alias for a colon. Then we could write code like:
>> 
>> 
>> def spam(arg);;
>>     for x in seq,,,,
>>         pass
> 
> Wouldn't it make more sense to use four periods?
> 
> def spam(arg)....
>     for x in seq....
>         pass
> 
> First, 2 colons is 4 dots, so it's conservation of punctuation.  Second,
> it reads pretty well.


Four periods .... is already legal, it is ellipsis followed by dot:

py> ....__class__
<class 'ellipsis'>


(Try it in Python 3, it actually works!)



-- 
Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web