1

I am getting not all arguments converted during string formatting, but my code is actually working. Can someone tell me what is wrong with my code? When I run this, it returns the error, but whenI look at the list wo workes by calling Query_Workers(), it appears that the person I chose had been removed successfully.

def Remove_Directors(id, name):

    conn = None
    try:
        # read the connection parameters
        params = config()
        # connect to the PostgreSQL server
        conn = psycopg2.connect(**params)
        cur = conn.cursor()
        # create table one by one
        #for command in commands:
        #    cur.execute(command)
        SQL = "DELETE FROM directors WHERE id = (%s);"
        #cur.execute("DELETE FROM directors WHERE id = (%s)", (id))
        id = (id, )
        cur.execute(SQL, id)
        # close communication with the PostgreSQL database server
        cur.close()
        # commit the changes
        conn.commit()
        print ("%s has been removed from Directors.") % (name)
    except (Exception, psycopg2.DatabaseError) as error:
        print(error)
    finally:
        if conn is not None:
            conn.close()

def Modify():

    print "Choose Options"

    option = raw_input("Press A for adding a member, R for removing a member, or V for Viewing members: ")
    if option.upper() == "A":
        print "Adding a member."
        Director_or_EventManager = raw_input("Is the new member a director or an event manager?\nPress D for Director or E for Event Manager:")
        if Director_or_EventManager.upper() == "D":
            ID_Entered_Correctly = False
            while ID_Entered_Correctly == False:
                id = raw_input("Enter 10 digit ID: ")
                if len(id) == 10:
                    ID_Entered_Correctly = True
                else:
                    print "Invalid ID"
            name = raw_input("Enter Name: ")
            Add_Directors(id, name)
        if Director_or_EventManager.upper() == "E":
            ID_Entered_Correctly = False
            while ID_Entered_Correctly == False:
                id = raw_input("Enter 10 digit ID: ")
                if len(id) == 10:
                    ID_Entered_Correctly = True
                else:
                    print "Invalid ID"
            name = raw_input("Enter Name: ")
            Add_Event_Managerss(id, name)

    elif option.upper() == "R":
        print "Removing a member."
        Director_or_EventManager = raw_input("Is the member a director or an event manager?\nPress D for Director or E for Event Manager:")
        if Director_or_EventManager.upper() == "D":
            conn = None
            try:
                params = config()
                conn = psycopg2.connect(**params)
                cur = conn.cursor()
                cur.execute("SELECT id, name FROM directors ORDER BY name")
                directors = cur.fetchall()
                print ("\tNumber\tID\t\tName")
                ids = []
                names = []
                count = 1
                for director in directors:
                    print ("\t%s\t%s\t%s") % (count, director[0], director[1])
                    ids.append(director[0])
                    names.append(directors[1])
                    count += 1
                cur.close()
            except (Exception, psycopg2.DatabaseError) as error:
                print(error)
            finally:
                if conn is not None:
                    conn.close()
            count -= 1
            num_director = int(raw_input("Enter the number of director to remove: "))
            if num_director <= 0 or num_director > count:
                print "Invalid entry"
            else:
                id = ids[num_director - 1]
                name = names[ids.index(id)]
                print id
                print name
                Remove_Directors(id, name)

    elif option.upper() == "V":
        Query_Workers()
    else:
        print "Invalid option"

1 Answer 1

1

The error seems to occur after the query, so it doesn't impact the data change, only the output debugging.

You just need to change those lines :

print ("%s has been removed from Directors.") % (name)

to

print ("%s has been removed from Directors." % name)

and also :

print ("\t%s\t%s\t%s") % (count, director[0], director[1])

to

print ("\t%s\t%s\t%s" % (count, director[0], director[1]))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.