On 25/09/05, ZIYAD A. M. AL-BATLY <[EMAIL PROTECTED]> wrote:
> On Sun, 2005-09-25 at 18:55 +0530, Krishna wrote:
> > When I try to run the following piece of code, I get a SyntaxError,
> > can someone help me out on this?
> >
> > try:
> > ... os.system("cls")
> > ... except:
> > ... print "Foo"
> > ... print "Bar"
> > Traceback ( File "<interactive input>", line 5
> > print "Bar"
> > ^
> > SyntaxError: invalid syntax
> >
> > What am I missing?
> >
> > Thanks in advance,
> > Kris
> What you're writing is this:
> try:
> os.system("cls")
> except:
> print "Foo"
> print "Bar"
>
> Which is wrong! Here's the correct way:
> try:
> os.system("cls")
> except:
> print "Foo"
> print "Bar"
>
>
> Note the indentation for "try:" and "except:"? They most be on the same
> level. This is how exception handling is done in Python.
>
> By the way, the last "print" statement, I didn't know if you want it to
> be printed all the time (like what I wrote it above) or just when
> there's an exception.
Think the mail system screwed up the formatting! But am fairly sure
that I have indented it correctly in the console. Try and Except are
in the column. Any other hints?
BTW, I had just added the last print statement to see how try...except worked.
Thanks for the response.
-Kris
>
> Ziyad.
>
>
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor