[Tutor] need help tracing a syntax error
Alan Gauld
alan.gauld at freenet.co.uk
Sat Mar 11 23:41:47 CET 2006
Hi,
It would help us a lot if you send us a cut n paste of the actual code,
not retyped versions. Particularly for syntax erros since a single wrong
character might be all that's wrong and when you retype it its OK.
I'm assuming you are retyping from the fact that you have uppercase
keywords etc which aren't valid Python.
Also for the error merssage can you cut n paste the full error since
they contain a lot of useful info, do not just give us a description of
the error.
> def vmod(a , b ):
> .r1 = b
> .r2 = a
> . m1 = 0
> .m2 = 1
> .q = Int(r1 / r2)
> .r3 = r1 - q * r2
> .m3 = m1 - q * m2
> .while r3 != 0:
> ...r1 = r2
> ...m1 = m2
> ...r2 = r3
> ...m2 = m3
> ...q = Int(r1 / r2)
> ...r3 = r1 - r2 * q
> ...m3 = m1 - m2 * q
> .If r2 == 1:
> ...If m2 < 0:
> .....return( m2 + b)
> ...Else:
> .....return( m2 )
> .Else:
> ...return( -r2 )
> I get the message
> syntax error
> in the line
>
> .If r2 == 1:
> However if I
> use the eval function in the shell, I get
>>>> eval("factor30")
> <module 'factor30' from 'c:\math\factoring\factor30.pyc'>
Sorry, what is the connection between evaluating the string function30
and the code above? function30 doesn't appear anywhere...
> and when I use help to look at the associated module,
>
> this function is not listed. It must be because of the syntax error.
Which function?
Do you mean that the function you have written is in a file called
function30.py?
If so then eval("function30") does not do anything with your function,
it simply evaluated the name function30 and identifies that it is a module.
But this next bit seems to suggest that this is not what you have done.
> NAME
> factor30
>
> FILE
> c:\math\factoring\factor30.py
> Give me some hint for why this is happening.
I feel the same way. Can you send us real code with the full error message
and explain where function30 fits into the picture. Preferrably posted as
plain text.
Otherwise I'm completely confused!
Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list