1

I can't work out what the problem here is. The error code I keep getting is "Wrong number of arguments during string formatting" however I'm personally not seeing anything wrong with it. Can anyone point me in the right direction? Thanks.

def film_function(number, film):
    connection = connect(host='localhost', user='root', \
                                 passwd='', db='survey')
    cursor = connection.cursor()

    sql = "SELECT * FROM persons, persons_films WHERE persons.person = persons_films.person AND number_of_films >= %s AND film = '%s' ORDER BY persons_films.person"

    cursor.execute(sql, [number], [film])
    rows = cursor.fetchall()
    if not rows:
        print ("No one in "+film+" found!")
    else:
        for row in rows:
            print row[0],"-", row[1]
    cursor.close()
    connection.close()

1 Answer 1

1

This...

cursor.execute(sql, [number], [film])

should be this:

cursor.execute(sql, [number, film])

You want to pass a single list of arguments, not individual lists each with a single argument.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for that. Not sure if you can help me with this but " print ("No one in "+film+" found!")" isn't working the way I want it to either. +film+ should have double quotes around it but the printed result only has single quotes even after I've attempted using single/double quotes together, triple quotes, etc. thoughts?
try print ('No one in "'+film+'" found!')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.