By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,629 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,629 IT Pros & Developers. It's quick & easy.

SyntaxError: Invalid Syntax.

P: n/a
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"
);

Nov 10 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
ronrsr wrote:
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.

--
Roberto Bonvallet
Nov 10 '06 #2

P: n/a
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()

ronrsr wrote:
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"
);
Nov 10 '06 #3

P: n/a
In <11*********************@k70g2000cwa.googlegroups. com>, ronrsr wrote:
def connect():
return = MySQLdb.connect (host = "db91x.xxxx.com",
^

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

Ciao,
Marc 'BlackJack' Rintsch
Nov 10 '06 #4

P: n/a
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-

ronrsr wrote:
here's some of t
Nov 10 '06 #5

P: n/a
ronrsr wrote:
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)
--
Roberto Bonvallet
Nov 10 '06 #6

P: n/a
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-


Roberto Bonvallet wrote:
ronrsr wrote:
thanks for the speedy answer. what i meant was:
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)
--
Roberto Bonvallet
Nov 10 '06 #7

P: n/a
the syntax error comes in the main program, in any line that follows
the import statement.
ronrsr wrote:
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-


Roberto Bonvallet wrote:
ronrsr wrote:
thanks for the speedy answer. what i meant was:
>
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)
--
Roberto Bonvallet
Nov 10 '06 #8

P: n/a
"ronrsr" <ro****@gmail.comwrote:
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>

Nov 10 '06 #9

P: n/a
ronrsr wrote:
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
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Nov 10 '06 #10

P: n/a

ronrsr wrote:
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.
>

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

bests,

r-sr-


Roberto Bonvallet wrote:
ronrsr wrote:
thanks for the speedy answer. what i meant was:
>
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)
--
Nov 10 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.