2

I am looking for a way to add three 0's to the end of all entries in one column of data using an update cursor in python. For instance, if all the entries in the column of data have a value of 123456. I need to add python code that will return 123456000.

I was able to subtract out the the last three digits to process the information originally using this:

    while row:
        value = row.GetValue("LD_MCPI")[:-3].strip()
        row.SetValue("LD_MCPI", value)
        rows.updateRow(row)
        row = rows.Next()

How can I modify the [:-3] section of the second line to yield the results I need?

Thanks for your time.

3
  • What kind of object is row? Commented Jan 25, 2012 at 17:26
  • Are the values integers? Can you just multiply them all by 1000? Commented Jan 25, 2012 at 17:29
  • are the value string? "123"+"000" == 123000. Commented Jan 25, 2012 at 17:31

1 Answer 1

2

If I am understanding your problem correctly, row.GetValue("LD_MCPI") will return a string, like "123456", and you want to set value to the string "123456000". You can do this by simply adding the string "000" to row.GetValue("LD_MCPI"):

value = row.GetValue("LD_MCPI") + "000"

If this is not what you are looking for, please clarify your question.

I am pretty confident that you are dealing with strings based on the slicing you use in your example, but if row.GetValue("LD_MCPI") returns an int you can multiply it by 1000 to add the three zeros.

value = row.GetValue("LD_MCPI") * 1000
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the help! That was the answer I needed.

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.