[Tutor] Help with tkinter application.

Michael P. Reilly arcege@speakeasy.net
Fri, 18 Jan 2002 09:03:40 -0500


On Fri, Jan 18, 2002 at 01:54:01PM +0530, lonetwin wrote:
> Hey Arcege,
>    Thanx for the reply, although it didn't quite work as you suggested, I got
> the general idea. Thanx to you TKSpell is ready. Have a look below ....you
> may even want to run it :) !!!
>    Also Eve, thanx for trying it out, the error you mentioned:
> 
> ===============================================
>  python tkinter_spell.py
>   File "tkinter_spell.py", line 51
>     label = Label(self, text=' '.join([ x for x in self.result]))
>                                             ^
> SyntaxError: invalid syntax
> ===============================================
>     most probably is because you are running python version 1.5, which does
> not understand list comprehensions which are just a short cut way of doing a
> particular thing to elements of a list.
> 
> Eg:
> >>> l = [ "A", "B", "C" ]
> >>> p = [ x.lower() for x in l ]
> >>> p
> ['a', 'b', 'c']
> 
>        makes sense ?? if it doesn't, ask.

List comprehensions are about the same as filter and map, just in
a different format.  I find the format to be less intuitive and
syntactically more confusing with 'for' and 'if' statements.

Also, string methods were added in 2.0, so ' '.join(...) would not
work either.

>>> l = [ "A", "B", "C" ]
>>> p = map(string.lower, l)
>>> p
['a', 'b', 'c']

And more importantly, both list comprehensions and the functional
mechanisms work with sequences, not just lists.  The list comprehension
above is the same as 'list(self.result)' and 'map(None, self.result)'.
But also, the join method works with any sequence.  You could have just
written:
  ' '.join( self.result )

As an aside, the "os.sys.exit()" function call should just be
"sys.exit()".

The program runs well tho.  Good job.

  -Arcege