Syntax error - what's wrong?

Jeff Bauer jbauer at rubic.com
Sun Oct 17 21:58:56 EDT 1999


Andre-John Mas wrote:
>  I have never programmed in Python before and need a quick crash
>  course. I am installing Redhat Linux 6.1 and I am getting a Python
>  related error.

Andre-John,

Your code worked when I pasted into to my editor
and ran under Solaris 2.6, Python 1.5.2.

Here is a slightly different version which should
accomplish the same goals:

def zfill(x, width):
    fmt = "%%0%dd" % width
    return fmt % int(x)

# optional test routine ...
if __name__ == '__main__':
    for x, width in [(12, 3), (-3, 3), (1, 6), ('17', 4)]:
        print "zfill(%s, %d) = %s" % \
              (x, width, zfill(x, width))

I tend to prefer downloading Python source and
compiling it, rather than rely on the Linux
distributions -- they always seem to leave out 
my favorite features. ;-)

Regards,

Jeff Bauer
Rubicon Research




More information about the Python-list mailing list