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),
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 --
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
"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
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" <
"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__'
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
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
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,
"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
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
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
12 matches
Mail list logo