Re: str vs dict API size (was 'Re: left padding zeroes on a string...')

2005-03-25 Thread Bengt Richter
On Sat, 26 Mar 2005 04:10:21 GMT, Ron_Adam <[EMAIL PROTECTED]> wrote: >On Fri, 25 Mar 2005 18:06:11 -0500, "George Sakkis" ><[EMAIL PROTECTED]> wrote: > >> >>I'm getting off-topic here, but it strikes me that strings have so many >>methods (some of which are >>of arguable utility, e.g. swapcase),

Re: str vs dict API size (was 'Re: left padding zeroes on a string...')

2005-03-25 Thread Ron_Adam
On Fri, 25 Mar 2005 18:06:11 -0500, "George Sakkis" <[EMAIL PROTECTED]> wrote: > >I'm getting off-topic here, but it strikes me that strings have so many >methods (some of which are >of arguable utility, e.g. swapcase), while proposing two useful methods >(http://tinyurl.com/5nv66) >for dicts --

Re: str vs dict API size (was 'Re: left padding zeroes on a string...')

2005-03-25 Thread Robert Kern
George Sakkis wrote: "Larry Bates" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Once it is in everyone is hesitant to take it out for fear of breaking someone's code that uses it (no matter how obscure). Putting in new methods should be difficult and require lots of review for that r

Re: str vs dict API size (was 'Re: left padding zeroes on a string...')

2005-03-25 Thread George Sakkis
"Larry Bates" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Once it is in everyone is hesitant to take it out for fear of > breaking someone's code that uses it (no matter how obscure). > Putting in new methods should be difficult and require lots > of review for that reason and so

Re: str vs dict API size (was 'Re: left padding zeroes on a string...')

2005-03-25 Thread Larry Bates
Once it is in everyone is hesitant to take it out for fear of breaking someone's code that uses it (no matter how obscure). Putting in new methods should be difficult and require lots of review for that reason and so we don't have language bloat. Larry Bates George Sakkis wrote: > "M.E.Farmer" <

str vs dict API size (was 'Re: left padding zeroes on a string...')

2005-03-25 Thread George Sakkis
"M.E.Farmer" <[EMAIL PROTECTED]> wrote: > > [snipped] > > Be sure to study up on string methods, it will save you time and > sanity. > Py> dir('') > ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', > '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', > '__gt__'

Re: left padding zeroes on a string...

2005-03-25 Thread Kent Johnson
cjl wrote: Hey all: I want to convert strings (ex. '3', '32') to strings with left padded zeroes (ex. '003', '032') In Python 2.4 you can use rjust with the optional fill argument: >>> '3'.rjust(3, '0') '003' In earlier versions you can define your own: >>> def rjust(s, l, c): ... return ( c*l

Re: left padding zeroes on a string...

2005-03-25 Thread John Machin
cjl wrote: > I want to convert strings (ex. '3', '32') to strings with left padded > zeroes (ex. '003', '032'), so I tried this: > > string1 = '32' > string2 = "%03s" % (string1) > print string2 > > >32 > > This doesn't work. Documentation == """ Flag Meaning 0 The conversion will be zero padded

Re: left padding zeroes on a string...

2005-03-25 Thread M.E.Farmer
Your first conversion works fine. string1 = '32' string2 = "%04s" % (string1) print string2 ' 32' Notice that it returns a string with spaces padding the left side. If you want to pad a number with 0's on the left you need to use zfill() '32'.zfill(4) '0032' Be sure to study up on string methods,

Re: left padding zeroes on a string...

2005-03-25 Thread George Sakkis
"cjl" <[EMAIL PROTECTED]> wrote: > Hey all: > > I want to convert strings (ex. '3', '32') to strings with left padded > zeroes (ex. '003', '032'), so I tried this: > > string1 = '32' > string2 = "%03s" % (string1) > print string2 > > >32 > > This doesn't work. Actually in this case string2 is pad

Re: left padding zeroes on a string...

2005-03-25 Thread Peter Hansen
cjl wrote: Hey all: I want to convert strings (ex. '3', '32') to strings with left padded zeroes (ex. '003', '032'), so I tried this: string1 = '32' string2 = "%03s" % (string1) string1.zfill(3) -Peter -- http://mail.python.org/mailman/listinfo/python-list

left padding zeroes on a string...

2005-03-25 Thread cjl
Hey all: I want to convert strings (ex. '3', '32') to strings with left padded zeroes (ex. '003', '032'), so I tried this: string1 = '32' string2 = "%03s" % (string1) print string2 >32 This doesn't work. If I cast string1 as an int it works: string1 = '32' int2 = "%03d" % (int(string1)) print