import argparse
import os
import re
import sys

def main(cmdline):

    parser = argparse.ArgumentParser(
        description='Ensure zero padding in numbering of files.')
    parser.add_argument('path', type=str,
        help='path to the directory containing the files')
    args = parser.parse_args()
    path = args.path

    numbered = re.compile(r'(.*?)(\d+)\.(.*)')

    numbered_fnames = [fname for fname in os.listdir(path)
                       if numbered.search(fname)]

    max_digits = max(len(numbered.search(fname).group(2))
                     for fname in numbered_fnames)

    for fname in numbered_fnames:
        _, prefix, num, ext, _  = numbered.split(fname, maxsplit=1)
        num = num.zfill(max_digits)
        new_fname = "{}{}.{}".format(prefix, num, ext)
        if fname != new_fname:
            os.rename(os.path.join(path, fname), os.path.join(path, new_fname))
            print "Renamed {} to {}".format(fname, new_fname)
        else:
            print "{} seems fine".format(fname)

if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))


@@ -1,12 +1,36 @@
+#!/usr/bin/env python3%0A%0A
 import argpa
@@ -65,16 +65,17 @@
 rt sys%0A%0A
+%0A
 def main
@@ -79,15 +79,8 @@
 ain(
-cmdline
 ):%0A%0A
@@ -211,15 +211,32 @@
 ent(
-'path',
+%0A        'path',%0A       
  typ
@@ -686,17 +686,16 @@
 , ext, _
- 
  = numbe
@@ -867,16 +867,33 @@
 .rename(
+%0A                
 os.path.
@@ -910,16 +910,32 @@
  fname),
+%0A               
  os.path
@@ -975,17 +975,17 @@
    print
- 
+(
 %22Renamed
@@ -1019,16 +1019,17 @@
 w_fname)
+)
 %0A       
@@ -1052,17 +1052,17 @@
    print
- 
+(
 %22%7B%7D seem
@@ -1082,16 +1082,17 @@
 t(fname)
+)
 %0A%0Aif __n
@@ -1134,20 +1134,7 @@
 ain(
-sys.argv%5B1:%5D
 ))%0A
-%0A

Convert to py3, fix style issues (flake8, pylint).