1

I checked similar questions in this error but none is useful here is my code :

def update(up_margin=None, margin=None, time=None, history=None, clean_type=None):
    update_column = ''

    columns = {'up_margin': up_margin, 'margin': margin, 'time': time, 'history': history, 'type': clean_type}
    for key, value in columns:
        if value is not None:
            if update_column != '':
                update_column += ','
            update_column += '{}={}'.format(key, value)
    print(update_column)

update(up_margin=100) 

2 Answers 2

4

You need to iterate over the items() of your dictionary.

Change your for loop to

for key, value in columns.items():
Sign up to request clarification or add additional context in comments.

Comments

2
def update(up_margin=None, margin=None, time=None, history=None, clean_type=None):
    update_column = ''

    columns = {'up_margin': up_margin, 'margin': margin, 'time': time, 'history': history, 'type': clean_type}
    for key, value in columns.items():
        if value is not None:
            if update_column != '':
                update_column += ','
            update_column += '{}={}'.format(key, value)
    print(update_column)

update(up_margin=100) 

When iterating over a map, use .items()

Comments

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.