[Tutor] broken script - curiouser and curiouser
Lisi
lisi.reisz at gmail.com
Wed Jul 6 23:57:25 CEST 2011
Thanks very much Martin. I did "solve" the problem after you kindly emailed -
but the solution has puzzled me more that the original problem.
On Tuesday 05 July 2011 23:23:41 Martin wrote:
> : lisi at Tux:~/Python/LearnPythonTheHardWay$ python ex26.py
> : File "ex26.py", line 10
> : def print_first_word(words)
> : ^
> : SyntaxError: invalid syntax
> : lisi at Tux:~/Python/LearnPythonTheHardWay$
>
> Look at the error. Look at the error carefully.
>
> Look at the definitions of your other functions....
>
> Compare. What is different?
I could see nothing that was different.
> do you see the colon?
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.
>
> def silly_function(args):
>
> Curiously, the sample that you pasted above has the required colon
> at the end of the line which starts the function definition.
>
> : def print_first_word(words):
> : """Prints the first word after popping it off."""
> : word=words.pop(0)
> : print word
>
> I have heard people express frustration many times about how a
> program(ming language) or "the computer" did not understand
> something because the thing was 'missing a damned semicolon'.
I know that the smallest difference matters when dealing with a computer but
could - and can - find none.
> Try again, keep with it, and recognize that these beasties are
> awfully particular in what they accept. And, for good reason.
I have no difficulty with the fact that computers are literal minded. They
are after all, machines. But "try again" was obviously great advice, and you
had given me the push I needed to try again when I had given up.
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. So I altered line six in the same way - and that still ran. So line
six will run either with or without the space. I then typed the next 2
sections in, and they ran, like line 6, either with or without the space.
So line 10 needs a space and the other sections are happy either with or
without. And they all have """ at the beginning of the next line.
You could obviously see something wrong that I had continued, and continue, to
miss, and I have still not found it. Hitting on the "right" solution almost
by serendipity doesn't really count as seeing something wrong!!
> Best of luck, Lisi,
Thanks again very much Martin. You really encouraged me.
I am obviously not going to get any further now, I am so bogged down in the
whole thing. So I think that I may need to pass on and come back to it
later.
Lisi
More information about the Tutor
mailing list