truncating strings

2011-08-23 Thread Roy Smith
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: log_message = message if len(log_message) = 50: log_message = log_message[:50] + '...' logger.error(FAILED: '%s', '%s', %s, %s %

Re: truncating strings

2011-08-23 Thread Chris Rebert
On Tue, Aug 23, 2011 at 9:29 AM, Roy Smith r...@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:          log_message = message          if len(log_message) = 50:            log_message =

Re: truncating strings

2011-08-23 Thread Seebs
On 2011-08-23, Roy Smith r...@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?

Re: truncating strings

2011-08-23 Thread Ethan Furman
Seebs wrote: On 2011-08-23, Roy Smith r...@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

Re: truncating strings

2011-08-23 Thread Seebs
On 2011-08-23, Ethan Furman et...@stoneleaf.us wrote: Seebs wrote: On 2011-08-23, Roy Smith r...@panix.com wrote: 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. Huh.

Re: truncating strings

2011-08-23 Thread Ethan Furman
Seebs wrote: On 2011-08-23, Ethan Furman et...@stoneleaf.us wrote: Seebs wrote: On 2011-08-23, Roy Smith r...@panix.com wrote: 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

Re: truncating strings

2011-08-23 Thread Steven D'Aprano
Seebs wrote: Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type help, copyright, credits or license for more information. print %.5s % (hello there, truncate me!) hello Well, whadda you know, I learned something new :) In any case, this

Re: truncating strings

2011-08-23 Thread Seebs
On 2011-08-23, Ethan Furman et...@stoneleaf.us wrote: Ah -- that's only part of it -- the OP wants '...' to print as well. :) O. Hmm. That's harder. I can't think of a pretty way, so I think I'd probably write a prettytrunc(string, len) or something similar. -s -- Copyright 2011, all

[issue1735418] file.read() truncating strings under Windows

2009-04-06 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: It's a bug in the program's logic. The program assumes that the file pointer will have advanced by the same number of bytes as were returned by read(), but it is false when opened in text mode ('r') since text mode under Windows will convert

[issue1735418] file.read() truncating strings under Windows

2009-04-06 Thread Daniel Diniz
Daniel Diniz aja...@gmail.com added the comment: Is this valid? -- nosy: +ajaksu2, benjamin.peterson, pitrou stage: - test needed type: - behavior versions: +Python 2.6, Python 3.1 ___ Python tracker rep...@bugs.python.org

[ python-Bugs-1735418 ] file.read() truncating strings under Windows

2007-06-14 Thread SourceForge.net
thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: cgkanchi (cgkanchi) Assigned to: Nobody/Anonymous (nobody) Summary: file.read() truncating strings under Windows

[ python-Bugs-1735418 ] file.read() truncating strings under Windows

2007-06-12 Thread SourceForge.net
, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: cgkanchi (cgkanchi) Assigned to: Nobody/Anonymous (nobody) Summary: file.read() truncating strings under Windows

[ python-Bugs-1735418 ] file.read() truncating strings under Windows

2007-06-12 Thread SourceForge.net
, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: cgkanchi (cgkanchi) Assigned to: Nobody/Anonymous (nobody) Summary: file.read() truncating strings under Windows

[ python-Bugs-1735418 ] file.read() truncating strings under Windows

2007-06-11 Thread SourceForge.net
of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: cgkanchi (cgkanchi) Assigned to: Nobody/Anonymous (nobody) Summary: file.read() truncating strings