[Tutor] can't run script (fwd)

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Fri Jan 31 03:55:01 2003


Hi Mike,

(side note: when you reply, make sure tutor@python.org is also in the
reply; that way, even if I get mauled by a large rat, you'll still have a
good chance of getting answers from the rest of the group)

Let's look at the code you attached:

### code
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
print "hello world"
print "Here are 10 numbers"
for i in range(10):
    print i
print "I'm done"
###


And here's the error message you sent me:

###
File "C:\Python22\hello128.py", line 1
    Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on
win32
             ^
SyntaxError: invalid syntax
###



Ah ha!  You'll need to drop the first few lines there from your program.
Those lines,

"""
   Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
   Type "copyright", "credits" or "license" for more information.
   IDLE 0.8 -- press F1 for help
"""

are part of the "greeting" that Python gives you when it starts up: they
are not actual program lines.  That's why Python's pointing to the first
greeting line: it's saying "these are not program statements."


If you clean up your program, it should look like:

###
print "hello world"
print "Here are 10 numbers"
for i in range(10):
    print i
print "I'm done"
###


Try that; you should get better results with it.  Hope this helps!



---------- Forwarded message ----------
Date: Fri, 31 Jan 2003 00:20:37 -0800
From: Mike Cluster <mjcluster@earthlink.net>
To: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] can't run script

Danny,
    Thanks for answering. Here are the files.

mike
-----Original Message-----
From: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
To: Mike Cluster <mjcluster@earthlink.net>
Cc: tutor@python.org <tutor@python.org>
Date: Thursday, January 30, 2003 10:03 PM
Subject: Re: [Tutor] can't run script


>
>
>On Tue, 28 Jan 2003, Mike Cluster wrote:
>
>> I am new to both programming and python, but I've been able to work in
>> interactive mode and make some progress. However I am unable to save and
>> "run script"- every time I try I get an "invalid syntax" error message.
>
>Hi Mike,
>
>When Python says "Invalid syntax", it means that the program doesn't quite
>know what to make of it.  *grin* But don't worry; that's what we're here
>for.
>
>
>We need to see what you've typed to better understand the problem.  Can
>you cut and paste your program and send it to the Tutor list?  You can
>copy it directly into the email body: we can take a look and see what's
>going on.  Also, there should have been a few lines of error message right
>above the "Invalid syntax" part --- can you send those lines over as well?
>
>
>> None of the tutorials seem to address this or anticipate it as a
>> problem.????????????? mike
>
>I wrote a tutorial on IDLE that does mention that SyntaxErrors can
>happen:
>
>    http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/
>
>As you learn more of the language, syntax errors will be easier to figure
>out.  Since you're new to the language, please feel free to show us on the
>Tutor list; we'll be happy to interpret the errors for you.
>
>
>Good luck!
>