Vong Ly
Vong Ly

Reputation: 187

Python Function IndentationError: unexpected indent

I'm having issues with an indent error in my code. It looks correct... can anyone point out what I'm doing wrong? I keep getting the error on the line of my query.

def invoice_details(myDeliveryID):

    conn = pymssql.connect(myMSSQLserver, myMSSQLuser, myMSSQLpassword, myMSSQLdatabase)
    cursor1 = conn.cursor()

    cursor1.execute('''My Query''' +  "'" + myDeliveryID + "'" + ''' More of my query...''')

    InvoiceDetails = cursor1.fetchone()

    myLocation = "%s" % (InvoiceDetails[0])
    myDate = "%s" % (InvoiceDetails[1])
    myInvoiceNumber = "%s" % (InvoiceDetails[2])
    myAccountNumber = "%s" % (InvoiceDetails[3])

    return myLocation
    return myDate
    return myInvoiceNumber
    return myAccountNumber

    conn.close()

Upvotes: 1

Views: 673

Answers (1)

alecxe
alecxe

Reputation: 474001

You cannot have multiple return statements in a function.

Instead, you probably meant to return InvoiceDetails (which is a tuple):

def invoice_details(myDeliveryID):
    conn = pymssql.connect(myMSSQLserver, myMSSQLuser, myMSSQLpassword, myMSSQLdatabase)
    cursor1 = conn.cursor()

    cursor1.execute('''My Query''' +  "'" + myDeliveryID + "'" + ''' More of my query...''')

    InvoiceDetails = cursor1.fetchone()

    conn.close()

    return InvoiceDetails

Or, you can make a namedtuple() to also have attribute lookups in addition to positional:

import collections

invoice = collections.namedtuple('Invoice', ['location', 'date', 'number', 'account_number'])
return invoice(*InvoiceDetails)

Also see:

Upvotes: 0

Related Questions