|
From: | Ahsan Rabbani |
Subject: | Re: [Fab-user] String formatting with color functions |
Date: | Mon, 21 Nov 2011 23:37:33 -0500 |
On Mon, Nov 21, 2011 at 3:40 PM, Ahsan Rabbani <address@hidden> wrote:My guess would be that it has something to do with the non-printing
> I've noticed that when printing strings that are wrapped in color functions
> it screws up the string formatting.
ANSI color escape codes that the color functions add. They're likely
"counting" as individual characters from the perspective of Python's
string formatter when it does the left-justify.
Offhand workarounds (caveat: I don't do a ton of string manip these
days...): manually calculating how the justification should occur
(based on the string before it is colorized) and adding the extra
spaces yourself; or doing a substitution (i.e. justify, then take the
result and substitute the original string for the colorized string.)
Hope that helps,
Jeff
--
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org
[Prev in Thread] | Current Thread | [Next in Thread] |