On Thursday 07 July 2011 00:48:24 Alan Gauld wrote: > "Lisi" <lisi.re...@gmail.com> wrote > > >> : File "ex26.py", line 10 > >> : def print_first_word(words) > >> : ^ > >> : SyntaxError: invalid syntax > >> : lisi@Tux:~/Python/LearnPythonTheHardWay$ > >> > >> Look at the error. Look at the error carefully. > > > > I could see nothing that was different. > > The error report says you had no colon in your code. > Python couldn't see it...
But there *was* a colon. So why couldn't python see it? > Are you sutre you didn't add it before posting but > after running the code? Positive. > Or are you testing it by impotrting a module? > In that case the interpreter may still be using > the old version because you haven't reloaded > the updated version? No > > Yes - it was one of the first things I looked for when > > the error came up (that and check that the brackets > > were right). It was there in what seemed to me > > to be the right position. > > In that case I suspect the module theory. > How are you running the code? $ python ex14.py > > In the end, having tried absolutely everything else > > I could think of, and given that the error arose at > > the closing bracket at the end of line 10, I > > tried the only thing I could remotely think of that > > I hadn't tried and put a space in between the > > second bracket and the colon - and the wretched thing > > ran. > > As you know that shouldn't have made any difference. > Did you try going back and removing the space again > and see if the error came back? I now have at your suggestion, and it runs. So I am now still more mystified. As I say I had tried retyping it (and checking carefully) umpteen times and also copied and pasted from a succesful function definition and checked the brackets and colon every time. > > You could obviously see something wrong > > The posted error report had no colon. Yes - but the script had one, which was why I included the actual script in my original post. I seem to have cut too much in this email! Thanks, Alan. Lisi _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor