Search code examples
pythonstringpython-2.7text-align

Rjust method alignment


Here is the simple code:

OS.write(ip+re.search(version,data).group(0).rjust(25)+'\n')

All I want is to have the output like this:

10.102.19.1           version=6.40.7
10.102.41.1           version=6.40.7
10.102.3.1            version=6.40.8

But have the right string absolutely doesnt want to be aligned and I always get this:

10.102.19.1           version=6.40.7
10.102.41.1           version=6.40.7
10.102.3.1           version=6.40.8

What I'm doing wrong?


Solution

  • A trivial solution might be,

    OS.write(ip + re.search(version, data).group(0).rjust(30 - len(ip)) + '\n')