So i am trying to take some code that i had working before and turn it into a function but every time i run my code it kicks it to line 9 in my code which is a continue statement and says the its not properly in the loop. I was wondering if someone could please explain to me where im goign wrong with this and how to fix it and if there are any other errors that would mess my code up.Any help would be greatly appriciated thank you.

def convertToSor(saleDate,Amount,Fname,Lname,Email,Franchise,osg,State,Postal,OrderID,DateAdded,EmailSource):
    for row in cf1:
    nr = newrow
    nr[saleDate] = row['LastOrderDate'].strip()
    nr[Amount] = row['LastOrderAmount'].strip()
    nr[Fname] = row['FirstName'].strip()
    nr[Lname] = row['LastName'].strip()
    nr[Email] = row['EmailAddress'].strip().split(',',1)[0]
    if nr[Email] == '':
        continue

    fr_name = row[Franchise].strip()
    if fr_name in franchiseList:
        nr[Franchise] = franchiseList[fr_name]['FRANCHISE Name'].strip()
        if nr[Franchise] == 'IGNORE':
            continue
        nr[osg] = franchiseList[fr_name]['FRANCHISE Name - Directory'].strip()
        if nr[osg] == '':
            nr[osg] = 'shop'
    else:
            nr[Franchise] = 'SHOP'
            nr[osg] = 'shop'

            nr[State] = row['State'].strip()
            nr[Postal] = row['ZIP'].strip()
            nr[OrderID] = row['WEBID'].strip()
            nr[DateAdded] = datetime.date.today().strftime('%m/%d/%Y')  
            nr[EmailSource] = 'FACTSauto'

    ur = updaterow
    ur[saleDate] = row['LastOrderDate'].strip()
    ur[Amount] = row['LastOrderAmount'].strip()
    ur[Fname] = row['FirstName'].strip()
    ur[Lname] = row['LastName'].strip()
    ur[Email] = row['EmailAddress'].strip().split(',',1)[0]
    if ur[Email] == '':
        continue

    fr_name = row[Franchise].strip()
    if fr_name in franchiseList:
        ur[Franchise] = franchiseList[fr_name]['FRANCHISE Name'].strip()
        if ur[Franchise] == 'IGNORE':
            continue
        ur[osg] = franchiseList[fr_name]['FRANCHISE Name - Directory'].strip()
        if ur[osg] == '':
            ur[osg] = 'shop'
    else:
            ur[Franchise] = 'SHOP'
            ur[osg] = 'shop'

            ur[State] = row['State'].strip()
            ur[Postal] = row['ZIP'].strip()
            ur[OrderID] = row['WEBID'].strip()
            return True

As the error message correctly points out, it is indeed not a inside a loop. In fact there is no loop anywhere in your function.

ok sepp2k i put the for loop that was with ti in the original workign version and it keeps giving me the same error. i have updated my code with the for loop in it.

Are you sure, you're getting the same error? Because from looking at the new code, I'd say you should be getting an indentation error now because you did not indent the body of the loop.

sorry that was my bad i ment to copy the whole code after i fixed the indent error. here is teh code with for loop and properly indented but still getting the error.

def convertToSor(saleDate,Amount,Fname,Lname,Email,Franchise,osg,State,Postal,OrderID,DateAdded,EmailSource):
    for row in cf1: 
        nr = newrow
    nr[saleDate] = row['LastOrderDate'].strip()
    nr[Amount] = row['LastOrderAmount'].strip()
    nr[Fname] = row['FirstName'].strip()
    nr[Lname] = row['LastName'].strip()
    nr[Email] = row['EmailAddress'].strip().split(',',1)[0]
    if nr[Email] == '':
        continue
    fr_name = row[Franchise].strip()
    if fr_name in franchiseList:
        nr[Franchise] = franchiseList[fr_name]['FRANCHISE Name'].strip()
    if nr[Franchise] == 'IGNORE':
        continue
    nr[osg] = franchiseList[fr_name]['FRANCHISE Name - Directory'].strip()
    if nr[osg] == '':
        nr[osg] = 'shop'
    else:
        nr[Franchise] = 'SHOP'
    nr[osg] = 'shop'            
    nr[State] = row['State'].strip()
    nr[Postal] = row['ZIP'].strip()
    nr[OrderID] = row['WEBID'].strip()
    nr[DateAdded] = datetime.date.today().strftime('%m/%d/%Y')  
    nr[EmailSource] = 'FACTSauto'

    ur = updaterow
    ur[saleDate] = row['LastOrderDate'].strip()
    ur[Amount] = row['LastOrderAmount'].strip()
    ur[Fname] = row['FirstName'].strip()
    ur[Lname] = row['LastName'].strip()
    ur[Email] = row['EmailAddress'].strip().split(',',1)[0]
    if ur[Email] == '':
        continue
    fr_name = row[Franchise].strip()
    if fr_name in franchiseList:
        ur[Franchise] = franchiseList[fr_name]['FRANCHISE Name'].strip()
    if ur[Franchise] == 'IGNORE':
        continue
    ur[osg] = franchiseList[fr_name]['FRANCHISE Name - Directory'].strip()
    if ur[osg] == '':
        ur[osg] = 'shop'
    else:
        ur[Franchise] = 'SHOP'
    ur[osg] = 'shop'                
    ur[State] = row['State'].strip()
    ur[Postal] = row['ZIP'].strip()
    ur[OrderID] = row['WEBID'].strip()
    return True

Now the body of the loop consists solely of nr = newrow - everything else is outside of the loop.

ok thanks that was my issue i gess cause now its working thanks for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.