truncating strings

Ethan Furman ethan at stoneleaf.us
Tue Aug 23 18:02:30 EDT 2011


Seebs wrote:
> On 2011-08-23, Roy Smith <roy at panix.com> wrote:
>> I want to log a string but only the first bunch of it, and add "..."
>> to the end if it got truncated.  This certainly works:
> 
>>           logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message,
>> route, params, e.code))
> 
>> does anything like this exist?
> 
> %.50s

That's not working in 2.7 or 3.2.

~Ethan~



More information about the Python-list mailing list