SyntaxError: Invalid Syntax.

R

ronrsr

no matter where I place this imported file,the statement after it in
the main program gets a syntax error, regardless of the syntax.

I think I may have changed something in this file, but I'm stuck. Can
anyone help?

#!/usr/local/bin/python
# Copyright 2004 by Stephen Masterman

#Change the db connection details here.


import MySQLdb




def connect():


return = MySQLdb.connect (host = "db91x.xxxx.com",
user = "xxxx",
passwd = "xxxxx",
db = "homebase_zingers"
);
 
R

Roberto Bonvallet

ronrsr said:
return = MySQLdb.connect (host = "db91x.xxxx.com",
user = "xxxx",
passwd = "xxxxx",
db = "homebase_zingers"
);

return is a reserved keyword. You cannot have a variable with that name.
 
R

ronrsr

here's some of the surrounding code from the main program:



querystring = querystring + " ORDER BY keywords ";
#SQL
import zsql





zc = zsql.connect()

print("return from open")



zq = zc.query(querystring).dictresult()
 
M

Marc 'BlackJack' Rintsch

def connect():


return = MySQLdb.connect (host = "db91x.xxxx.com",
^

You can't assign to a keyword. Just leave this ``=`` out.

Ciao,
Marc 'BlackJack' Rintsch
 
R

ronrsr

thanks for the speedy answer. what i meant was:

return MySQLdb.connect (host = "db91b.pair.com",
user = "homebase",
passwd = "Newspaper2",
db = "homebase_zingers"
);


but even when I have that, I still get the same error.

bests,

-rsr-
 
R

Roberto Bonvallet

ronrsr said:
thanks for the speedy answer. what i meant was:

return MySQLdb.connect (host = "db91b.pair.com",
user = "homebase",
passwd = "Newspaper2",
db = "homebase_zingers"
);


but even when I have that, I still get the same error.

Could you please copy and paste the exact code that is triggering the
error, and the exact error message?

(BTW, in Python you don't need to end your statements with a semi-colon)
 
R

ronrsr

the exact code that is triggering the error message is:

zc = zsql.connect()


exact error message: SyntaxError: Invalid Syntax


but any statement that follows the import statement will trigger it.

bests,

r-sr-
 
R

ronrsr

the syntax error comes in the main program, in any line that follows
the import statement.
 
F

Fredrik Lundh

ronrsr said:
the exact code that is triggering the error message is:

zc = zsql.connect()

individual statements don't "trigger" syntax errors; they're compiler
errors, and only
appear when do something that causes code to be compiled.
exact error message: SyntaxError: Invalid Syntax

a complete syntax error usually includes a traceback:

Traceback (most recent call last):
File "program.py", line 1, in <module>
import module
File "module.py", line 25
if 1
^
SyntaxError: invalid syntax

what does the traceback look like in your case?

</F>
 
S

Steve Holden

ronrsr said:
the syntax error comes in the main program, in any line that follows
the import statement.
in which case, don't you think it might be the "import" statement that's
causing the problem. What is stopping you from showing us the whole
source? Or at least the import statement as well as the statement that
causes the syntax error to be reported. Maybe your module has an odd
name like "from", for example.

We aren't psychic, you know (though some on this list come close).

regards
Steve
 
J

John Machin

ronrsr said:
the exact code that is triggering the error message is:

zc = zsql.connect()

Don't give us one line; give us the whole of the imported module plus
the calling script (at least up to the place where it gets the error).
That way we can see what is really going on, and someone with mysqldb
installed could try to reproduce your problem.
exact error message: SyntaxError: Invalid Syntax

Inexact! The message would have been
SyntaxError: invalid syntax

Please *DON'T* type in what you think you remember you think you saw on
the screen; *COPY/PASTE* the traceback and the error message.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top