Re: simple string formatting question

2007-12-14 Thread Neil Cerutti
On 2007-12-14, Neal Becker <[EMAIL PROTECTED]> wrote: > I have a list of strings (sys.argv actually). I want to print them as a > space-delimited string (actually, the same way they went into the command > line, so I can cut and paste) > > So if I run my program like: > ./my_prog a b c d > > I wan

Re: simple string formatting question

2007-12-14 Thread Gary Herron
Neal Becker wrote: > I have a list of strings (sys.argv actually). I want to print them as a > space-delimited string (actually, the same way they went into the command > line, so I can cut and paste) > > So if I run my program like: > ./my_prog a b c d > > I want it to print: > > './my_prog' 'a'

Re: simple string formatting question

2007-12-14 Thread Bruno Desthuilliers
Neal Becker a écrit : > I have a list of strings (sys.argv actually). I want to print them as a > space-delimited string (actually, the same way they went into the command > line, so I can cut and paste) > > So if I run my program like: > ./my_prog a b c d > > I want it to print: > > './my_prog

Re: Simple string formatting question

2006-04-07 Thread Peter Otten
Steven D'Aprano wrote: > I have a sinking feeling I'm missing something really, > really simple. > > I'm looking for a format string similar to '%.3f' > except that trailing zeroes are not included. > > To give some examples: > > FloatString > 1.0 1 > 1.1 1.1 > 12.1234

Re: Simple string formatting question

2006-04-06 Thread Fredrik Lundh
Paul McGuire wrote: > Ooops, don't combine the two calls to rstrip(). > > def format(f, width=3): return ("%.*f" % (width, f)).rstrip(".0") > > print format(3.140) > print format(3.000) > print format(3.001) > print format(30.) > print format(30.000) hey, I'm doing test-driven develop

Re: Simple string formatting question

2006-04-06 Thread Ben Finney
"Steven D'Aprano" <[EMAIL PROTECTED]> writes: > On Thu, 06 Apr 2006 22:16:05 +1000, Ben Finney wrote: > > "Steven D'Aprano" <[EMAIL PROTECTED]> writes: 1> >> I'm looking for a format string similar to '%.3f' except that > >> trailing zeroes are not included. > > > > Can;t be done, to my knowledge

Re: Simple string formatting question

2006-04-06 Thread Steven D'Aprano
On Thu, 06 Apr 2006 22:16:05 +1000, Ben Finney wrote: > "Steven D'Aprano" <[EMAIL PROTECTED]> writes: >> I'm looking for a format string similar to '%.3f' except that >> trailing zeroes are not included. > > Can;t be done, to my knowledge. You specify a particular precision, > and the number wil

Re: Simple string formatting question

2006-04-06 Thread Paul McGuire
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Steven D'Aprano wrote: > > > Here is a (quick and dirty) reference implementation: > > > > def format(f, width=3): > > fs = '%%.%df' % width > > s = fs % f > > return s.rstrip('0').rstrip('.') > > > > Is there

Re: Simple string formatting question

2006-04-06 Thread Fredrik Lundh
Steven D'Aprano wrote: > Here is a (quick and dirty) reference implementation: > > def format(f, width=3): > fs = '%%.%df' % width > s = fs % f > return s.rstrip('0').rstrip('.') > > Is there a way of getting the same result with just a > single string format expression? not with % it

Re: Simple string formatting question

2006-04-06 Thread Ben Finney
"Steven D'Aprano" <[EMAIL PROTECTED]> writes: > I have a sinking feeling I'm missing something really, really > simple. "Oh no, everyone in the galaxy gets that, that's perfectly natural paranoia." > I'm looking for a format string similar to '%.3f' except that > trailing zeroes are not included