Vines, John (Civ, ARL/CISD) wrote on Mon, 4 Apr 2005 10:04:59 -0400:
> Hello. I have a question regarding strings. How do I format a string to be a
> specific length?
> For example I need 'string1' to be 72 characters long.
You could do (I'll use 20 instead of 72 to keep it readable):
>>> s = "%20s" % "xyz"
>>> len(s), s
(20, ' xyz')
or:
>>> s = "xyz"
>>> s = s + (20 - len(s)) * ' '
>>> s, len(s)
('xyz ', 20)
--
Yours,
Andrei
=====
Real contact info (decode with rot13):
[EMAIL PROTECTED] Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor