type float problem

Robert Kern robert.kern at gmail.com
Fri Mar 27 01:54:37 CET 2009


On 2009-03-26 19:27, rolandschulz wrote:
> On Mar 26, 2:41 pm, Pavol Juhas<pavol.ju... at gmail.com>  wrote:
>> This has nothing to do with numpy, the issue is the string "%"
>> operator
>> cannot convert list to a float (Line 3 in your example gives a list).
>> In '"%f" % x' the x has to be a number or tuple.
>>
>> Does not work:
>>      print "%f" % [1.0]
>
> Yes that helps. Why is it that the %-operator requires a tuple and
> does not work with a list?
>
> Thus why doesn't this work: "%d %d"%[2,2]
> but instead it has to be: "%d %d"%tuple([2,2])
> or: "%d %d"%(2,2)

Allowing only a single sequence type to represent a collection of arguments for 
interpolation (as opposed to a single argument for a single % interpolation 
marker) helps resolve some ambiguities:

   '%s' % ['something']
   '%s' % ('something',)

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list