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' 'a' 'b'
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' 'b' 'c'
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 want it to
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 development. being
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
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.
Can;t
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 % itself,
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 a way of getting the
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 will be
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. You specify a
10 matches
Mail list logo