SyntaxError: Invalid Syntax.

Discussion in 'Python' started by ronrsr, Nov 10, 2006.

  1. ronrsr

    ronrsr Guest

    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"
    );
    ronrsr, Nov 10, 2006
    #1
    1. Advertising

  2. 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
    Roberto Bonvallet, Nov 10, 2006
    #2
    1. Advertising

  3. ronrsr

    ronrsr Guest

    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"
    > );
    ronrsr, Nov 10, 2006
    #3
  4. In <>, 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
    Marc 'BlackJack' Rintsch, Nov 10, 2006
    #4
  5. ronrsr

    ronrsr Guest

    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
    ronrsr, Nov 10, 2006
    #5
  6. 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
    Roberto Bonvallet, Nov 10, 2006
    #6
  7. ronrsr

    ronrsr Guest

    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
    ronrsr, Nov 10, 2006
    #7
  8. ronrsr

    ronrsr Guest

    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
    ronrsr, Nov 10, 2006
    #8
  9. "ronrsr" <> wrote:

    > 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>
    Fredrik Lundh, Nov 10, 2006
    #9
  10. ronrsr

    Steve Holden Guest

    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
    Steve Holden, Nov 10, 2006
    #10
  11. ronrsr

    John Machin Guest

    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)
    > > --
    John Machin, Nov 10, 2006
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DIBS

    SyntaxError: invalid syntax

    DIBS, Dec 27, 2005, in forum: Python
    Replies:
    5
    Views:
    39,347
    Terry Hancock
    Dec 27, 2005
  2. Replies:
    3
    Views:
    1,639
  3. Python Newsgroup

    SyntaxError: invalid syntax (windows)

    Python Newsgroup, Mar 25, 2009, in forum: Python
    Replies:
    6
    Views:
    1,241
    Terry Reedy
    Mar 25, 2009
  4. nicklancer

    SyntaxError: invalid syntax

    nicklancer, Apr 26, 2011, in forum: Python
    Replies:
    0
    Views:
    590
    nicklancer
    Apr 26, 2011
  5. Replies:
    9
    Views:
    329
    Karim
    Jan 10, 2013
Loading...

Share This Page