[Tutor] Help - My First Program Fails

tayo rotimi finsolut2003 at yahoo.com
Mon Sep 10 00:56:22 CEST 2012


My first exercise: print "Game Over" does not run! Where have I missed it? The error message is as follows:

 File "<stdin>", line 1
   print "Game Over"
                    ^
 SyntaxError: invalid syntax 


I am still surprised at this error. I 'll appreciate your help.

Regards.

Tayo



________________________________
 From: "tutor-request at python.org" <tutor-request at python.org>
To: tutor at python.org 
Sent: Sunday, September 9, 2012 10:14 PM
Subject: Tutor Digest, Vol 103, Issue 40
 
Send Tutor mailing list submissions to
    tutor at python.org

To subscribe or unsubscribe via the World Wide Web, visit
    http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
    tutor-request at python.org

You can reach the person managing the list at
    tutor-owner at python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

   1. Re: Help with class in class (leam hall)
   2. Re: I Need Help - further details now provided. (Matthew Ngaha)
   3. web frameworks (Matthew Ngaha)
   4. Re: web frameworks (Steven D'Aprano)
   5. Re: Help with class in class (leam hall)
   6. Re: web frameworks (Matthew Ngaha)
   7. Re: Help with class in class (Dave Angel)


----------------------------------------------------------------------

Message: 1
Date: Sun, 9 Sep 2012 14:12:48 -0500
From: leam hall <leamhall at gmail.com>
To: tutor <tutor at python.org>
Subject: Re: [Tutor] Help with class in class
Message-ID:
    <CACv9p5rm28NvdNHZyFD4pmdEqJmhzsjzjQHidde5MCm70o78aA at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Sun, Sep 9, 2012 at 12:12 PM, Peter Otten <__peter__ at web.de> wrote:

> the above will no longer complain about a missing attribute.
>
> > root = Tk()
> > project = ch8_Project(master=root)
> > project.mainloop()
>
>
> Another problem that caught my attention:
>
> >     self.green = Button(root, text="Green",
> command=self.change_text_color("green"))
>
>
> The command argument is supposed to be a function; you are instead
> assigning
> the result of a method call (which is None in this case, but as a side
> effect will set the color to green immediately. The simplest fix is to
> define a helper function that takes no arguments
>      ...
>      def change_to_green():
>          self.change_text_color("green")
>      self.green = Button(root, text="Green", command=change_to_green)
>      ...
>
> If you already know about lambda you can try to rewrite this using that.
>
>
Peter, thank you for helping me understand the scope issue I was missing! I
knew it was something like that but forget that omitting "this." meant the
variables were limited in scope to that method.

I have seen lamba but do not understand it. The project requires four
buttons, each one turns the same text a different color. The class is also
Python 3 based.  :)

Leam



-- 
Mind on a Mission <http://leamhall.blogspot.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120909/94464518/attachment-0001.html>

------------------------------

Message: 2
Date: Sun, 9 Sep 2012 20:20:19 +0100
From: Matthew Ngaha <chigga101 at gmail.com>
To: tutor at python.org
Subject: Re: [Tutor] I Need Help - further details now provided.
Message-ID:
    <CACzNyA0WsuSr3jUXJ46hNL1TtbKfCYK=BQtc+e-y_TRp2s8cAQ at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

SORRY i wrote to you not the mailing list:(

im a beginner myself, and those instructions seem very complicated for
me. But i did install Python and everything included with no problem.
You need at least Python 3.1 for this book we have. its what the
author recommended. version 2.7 as you have shown in the link is too
old as it has different syntax. Try downloading Python from the link i
included, you will have no trouble installing IDLE with this link.


------------------------------

Message: 3
Date: Sun, 9 Sep 2012 20:41:24 +0100
From: Matthew Ngaha <chigga101 at gmail.com>
To: tutor at python.org
Subject: [Tutor] web frameworks
Message-ID:
    <CACzNyA1t=P5gPrFDAV-mejQuA-QYB-LQVcYG-BVYQQdXKpbU9g at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi all, i had a recent post about learning about guis and web
applications. i decided to try guis 1st, but i also decided that maybe
a very very very simple web framework would not be too much work for
me to study once in  while. I decided on Flask because i read it's the
simpliest framework out of all the others i've researched, only to
find out it's not supported on Python 3:(.. i wondered if someone with
experience can tell me, in their opinion a framework with a similar
learning curve to Flask that a beginner can easily understand and is
supported on Python 3. i thought cherrypy, but was told it's not
nearly as simple as Flask, and since my main focus is learning GUIs, a
simple web framework will be ideal only to understand how they work. i
understand Javascript  only a little, but html and css a bit better
etc..

also is mod_python similar to a framework? does it perform the same
tasks and also make good web applications? would this be a better
option?


------------------------------

Message: 4
Date: Mon, 10 Sep 2012 06:29:50 +1000
From: Steven D'Aprano <steve at pearwood.info>
To: tutor at python.org
Subject: Re: [Tutor] web frameworks
Message-ID: <504CFC3E.2040701 at pearwood.info>
Content-Type: text/plain; charset=UTF-8; format=flowed

On 10/09/12 05:41, Matthew Ngaha wrote:

> [...] i thought cherrypy, but was told it's not
> nearly as simple as Flask, and since my main focus is learning GUIs, a
> simple web framework will be ideal only to understand how they work.

Understanding *how they work* is not going to be simple. Web frameworks
are big, complex pieces of software.

Being *able to use them* can be simple. Here's the "Hello world" example
for Cherrypy:

import cherrypy
class HelloWorld(object):
     def index(self):
         return "Hello World!"
     index.exposed = True

cherrypy.quickstart(HelloWorld())


I doubt Flask is simpler than that.



-- 
Steven


------------------------------

Message: 5
Date: Sun, 9 Sep 2012 15:56:26 -0500
From: leam hall <leamhall at gmail.com>
To: tutor <tutor at python.org>
Subject: Re: [Tutor] Help with class in class
Message-ID:
    <CACv9p5qOf+m4M8qJ3omKmHVNqXF2nYuW=uhNx6XXw4zJYg0BPQ at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

    self.blue = Button(root, text="Blue",
command=self.change_text_color("blue"))
    self.blue.pack(side=LEFT)
    self.green = Button(root, text="Green",
command=self.change_text_color("green"))
    self.green.pack(side=LEFT)

To follow up, I've added a second button. Of course, it doesn't work, the
text comes out as the color of the last button. It is running the commands
in the Button line without the buttons being clicked.

More research...


-- 
Mind on a Mission <http://leamhall.blogspot.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120909/8e3d69ce/attachment-0001.html>

------------------------------

Message: 6
Date: Sun, 9 Sep 2012 22:07:30 +0100
From: Matthew Ngaha <chigga101 at gmail.com>
To: tutor at python.org
Subject: Re: [Tutor] web frameworks
Message-ID:
    <CACzNyA3hjV_2-8Ck6kCM+Xcffg-zUqy1JyLua7Q2XgdYy2mEnw at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

sorry steven i keep replying to sender and not tutor:(


------------------------------

Message: 7
Date: Sun, 09 Sep 2012 17:13:37 -0400
From: Dave Angel <d at davea.name>
To: leam hall <leamhall at gmail.com>
Cc: tutor <tutor at python.org>
Subject: Re: [Tutor] Help with class in class
Message-ID: <504D0681.6060208 at davea.name>
Content-Type: text/plain; charset=ISO-8859-1

On 09/09/2012 04:56 PM, leam hall wrote:
>     self.blue = Button(root, text="Blue",
> command=self.change_text_color("blue"))
>     self.blue.pack(side=LEFT)
>     self.green = Button(root, text="Green",
> command=self.change_text_color("green"))
>     self.green.pack(side=LEFT)
>
> To follow up, I've added a second button. Of course, it doesn't work, the
> text comes out as the color of the last button. It is running the commands
> in the Button line without the buttons being clicked.
>
> More research...
>
>

Please reread Peter's message, starting with "Another problem..."

He identifies the problem, and mentions one way to fix it.  In your
response, you mentioned to lambda, so you must have seen it.

In particular, the Button() function takes a function object as its
command= parameter.  You call the function yourself, and pass the return
value, which of course is not what's wanted.  You don't want the
function called till someone presses the button.  So you want something
equivalent to
      = Button(root, text="Blue", command=change_to_green)

Notice that there are NO parentheses on that change_to_green.  You want
the function object, you do NOT want to call the function.



-- 

DaveA



------------------------------

Subject: Digest Footer

_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor


------------------------------

End of Tutor Digest, Vol 103, Issue 40
**************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120909/6c5e4bd1/attachment-0001.html>


More information about the Tutor mailing list