2

I have a field that has three entries as strings: "278957", "278961", and "12345678". When I use if/elif/else I can correctly replace the first two conditions in my code below but the problem is that for all entries that do not meet the conditions the values are replaced with . I thought writing "else: dsm == dsm" would preserve the original values if no conditions were met but it instead it overwrites the values to . Where am I going wrong?

def ifDSM(dsm): if dsm == "278957": return "10002343" elif dsm == "278961": return "10000550" else: dsm == dsm

7

dsm == dsm is a relational operator that will always be true but returns nothing.

Change your code to:

else:
    return dsm
0

It looks like on the last line you're doing a comparison operator rather than an assignment, perhaps this is messing up your "else" somehow.

Instead of assigning the value to itself, however, I might use a python continue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.