Re: [Tutor] need help tracing a syntax error
There was no actual message. The syntax error message to me occurred in a dialog box which closed immediately. What development tool are you using? I would change it, if it doesn't display a full error trace then it is depriving you of one of the most useful tools in Python! It's not possible to copy and paste a highlight. There was no error message except for the fact that r2 was highlighted. And how was the r2 highlighted? Again, what tool are you using? If you must stick with that tool then at least try running your code through the standard Python interpreter which will let you see the full error message, you can then paste that to us. Anyway, now I understand about uppercase and lower case, so I won't get a syntax error for this reason again. True, but there are many possible errors that you will get and not being able to clearly see the error text will be a big handicap to you and to us if you post a query. Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] need help tracing a syntax 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 ) When I attempt to run this function from the shell run menu, I get the message syntax error and it highlightsr2 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' no error message. and when I use help to look at the associated module, this function is not listed. It must be because of the syntax error. help(factor30) Help on module factor30: NAME factor30 FILE c:\math\factoring\factor30.py FUNCTIONS factor(z) factor0(z) gcd(a, b) ifprime(z) ksqrt(j) test(tv) transfac(v) Give me some hint for why this is happening. The periods at the beginning of each line represents beginning spaces. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help tracing a syntax error
I get the message syntax error and it highlightsr2 in the line .If r2 == 1: Hi Kermit, Next time, rather than describe the error message here in paraphrase, please copy-and-paste it in. Your paraphrase of the situation here hides useful information. We would rather that you give it to us straight and unfiltered. (Gosh, I sound like I'm in a bar or something. *grin*) I can see a problem, but I'm not sure if it's the only one. Keywords are case sensitive. 'If' is different than 'if'. You're using 'If', which is not a keyword, so what Python is seeing is essentially: some_variable_name another_variable_name which is illegal syntax in Python. Python can't tell that 'If' is meant to be the keyword 'if', so the closest it can say is that something weird happened as it was reading up to 'r2', so that's why the syntax error arrow is pointing at r2 rather than the 'If'. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help tracing a syntax error
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 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help tracing a syntax error
[CC'd to the list...] 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. no error message was provided. It only highlighted the variable in the If statement. But that's exactly what we need to see. Do not describe the error send the actual message including the line that it highlights. There are often subtle hints in those messages that help pinpoint the error, so simply saying it was a syntax error and what was highlighted is not as useful as sending us the actual text of the error. In this case it wouldn't have made much difference since it was the uppercase keywords, but in other scenarios it might make all the difference. I can't emphasise this enough, including the complete actual error message is one of the most useful things you can do to help us help you. Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor