Greg Ewing wrote:
> Barry Warsaw wrote:
> 
>> I don't much like the $"" prefix
> 
> This was discussed during the last round of formatting
> wars, and the conclusion was that having $ both
> inside and outside the string would be too visually
> confusing.
> 
>> I don't see a good
>> way to marry the rich coercion of %-substitution with the simplicity of
>> $-substition.
> 
> If I were designing a formatting system from scratch,
> I think I'd separate the issue of formatting numbers into
> strings from the issue of inserting strings into other
> strings. So instead of
> 
>    "Answer no. %5d is %8.3f" % (n, x)
> 
> you would say something like
> 
>    subst("Answer no. {1} is {2}", format(i, 'd', 5), format(x, 'f', 8, 3))
> 


And yet another (I'm sure there are many more) ways to look at it...

Consider "format" could be used to build strings from data, while 
"insert" could be used to put data into strings.  Then you can build 
strings in either direction depending on which fits the problem better.


Format data using string:

      (n, x).format("Anser no. {d:5} is {f:8.3}")


Insert data into string:

      "Anser no. {d:5} is {f:8.3}".insert(n, x)



If you want to separate the formating from the string further:

      (n, x).format('d:5', 'f:8.3').format("Answer no. {} is {}.")

      {n, x).format({1:'d:5', 2:'f:8.3'})       \
            .format("Answer no. {1} is {2}.")

      "Answer no. {} is {}.".insert('d:5', 'f:8.3').insert(n, x)

      "Answer no. {1} is {2}.".insert({1:'d:5', 2:'f:8.3'}) \
                             .insert(n, x)


And with data structures:

      string = "Answer no. {1} is {2}."
      forms = {1:'d:5', 2:'f:8.3'}
      data = (n, x)

      string.insert(forms).insert(data)

      data.format(forms).format(string)



I think I'd rather have dot separated format attributes.  They would be 
easy to parse or build with join or split, but considering how short 
they are it may not matter.

     {1:d.5}
     {2:f.8.3}




Cheers,
   Ron

_______________________________________________
Python-3000 mailing list
Python-3000@python.org
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