Greg Ewing wrote:
> Talin wrote:
> 
>>     s = str.convert( f, "2.2g" )
> 
> If format is a string method, then you will already be
> able to do
> 
>    s = str.format("2.2g", f)
> 
> if you want.

Nope. Given the current PEP, it'd have to be one of the following:

   s = "{0:2.2g}".format(f)
   s = str.format("{0:2.2g}", f)

However, I realised that there's an approach that is aesthetically pleasing 
and doesn't require using str() for this - simply consider the leading '{0:' 
and trailing '}' to be implicit if there are no braces at all in the supplied 
format string.

Then you could do things like:

 >>> "b".format(10)
1010
 >>> "o".format(10)
12
 >>> "x".format(10)
a
 >>> "X".format(10)
A
 >>> "2.2g".format(10)
10.00

Cheers,
Nick.

-- 
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to