New Python 3.0 string formatting - really necessary?

Michael Torrie torriem at gmail.com
Fri Dec 19 18:25:30 CET 2008


r wrote:
> if 3.0 looks like... print( "{0}={1}".format('this',99)) , WTF...
> thats retarded and looks like Ruby code. Thats not intuitive thats
> madness! What happens when you need a conversion to string from an
> integer, more code?? My faith is slipping. Have the python Gods gone
> mad??. Please tell me i am wrong.


You are wrong.

> 
> Pythons likeness to C is one of its great powers. I always thought of
> Python as an intuitive way to write C code.

I have to confess, I have no idea what you are talking about.  I have
never ever seen Python as an intuitive way to write C code.  That's kind
of bizarre.

> I am sticking with 2x(which i had planned to do anyway) I have heard
> of nothing significant enough to compel me to make the change yet. And
> with that example from 3.0, i am really setting my ways now. i may
> have to support the continuation of 2.x beyond 2.9.

> Guido! please don't play Russian roulette with Python! I have loved
> python all the way up through the 2.x line. And i carry a great
> respect for you and your accomplishments. Python must feel at home to
> a C programmer. That, i feel, is the professional following for
> Python. I also feel Python is a gateway to the C language for n00b
> programmers. Let Ruby have the Perl programmers, we don't need them!
> 
> Excuse me, I think i am going to cry now :(

Okay, you're welcome to.

So funny that now that Python 3.0 is actually released we have people
acting all surprised like they've never seen any of the new features in
Python 3.0 coming.  However these features have been discussed for
years!  And debated!

Personally the new string formatter is sorely needed in Python.  And
they way it has been implemented is a thing of beauty.  Basically the
burden of formatting strings has been moved from the print
statement/function to the objects themselves.  Furthermore, the new {}
notation allows many, many more options for formatting to be used.  Want
to display a floating point number with $#.## notation, and ($#.##) for
negative?  It's all now possible.  Couldn't be done before.  Want to
have the ability to format your own custom object in a particular way
when printing with print()?  Just define a __format__ method in your
object.  print() will ask it to format itself.

In short, this is a huge improvement, and backwards compatibility is
preserved for the 2.x style for those that wish it.




More information about the Python-list mailing list