How to increment a numeric string '0000000001' in python?

increment, python, string

Solution

You could convert the string to an int and use something like

self.seq = '%010d' % (int(self.seq) + 1)
return self.seq

If you didn't need `self.seq` to be a string you could do

def __init__(self) :
    self.seq = 0

def getNextSeqNo(self) :
    self.seq += 1
    return '%010d' % self.seq

Problem

I have a function `getNextSeqNo()`. I want it to increment the numeric string when it is called, i.e. `0000000000` to `0000000001`, and then to `0000000002`. How do I do it? I have written it as follows: ``` def __init__(self) : self.seq = '0000000000' def getNextSeqNo(self) : self.seq = str(int(self.seq) +1) return(self.seq) ``` I am getting 1 as the output instead of `0000000001`.

Original source