Tool for converting %-formatting to .format()ing ?

Is there a tool available that can convert 2.x code automagically to the .format() method syntax ? Just did a quick grep of our code base and it has some 2000 lines of code that would need to be changed. Thanks, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, May 09 2008)
Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611

mal> Is there a tool available that can convert 2.x code automagically mal> to the .format() method syntax ? mal> Just did a quick grep of our code base and it has some 2000 lines mal> of code that would need to be changed. I suggested a 2to3 fixer for this but was shot down. Skip

On 2008-05-09 15:29, skip@pobox.com wrote:
mal> Is there a tool available that can convert 2.x code automagically mal> to the .format() method syntax ?
mal> Just did a quick grep of our code base and it has some 2000 lines mal> of code that would need to be changed.
I suggested a 2to3 fixer for this but was shot down.
Well, ideally such a tool should address 2to2 :-) -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, May 09 2008)
Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611

On 2008-05-09 15:29, skip@pobox.com wrote:
mal> Is there a tool available that can convert 2.x code automagically mal> to the .format() method syntax ?
mal> Just did a quick grep of our code base and it has some 2000 lines mal> of code that would need to be changed.
I suggested a 2to3 fixer for this but was shot down.
Well, ideally such a tool should address 2to2 :-)
The curse of back-porting... I, too, would find such a tool helpful; I've got a thousand lines of %-formatting use just in UpLib alone. Bill

On Fri, May 09 2008 at 10:29:17AM BRT, skip@pobox.com wrote:
mal> Is there a tool available that can convert 2.x code automagically mal> to the .format() method syntax ?
mal> Just did a quick grep of our code base and it has some 2000 lines mal> of code that would need to be changed.
I suggested a 2to3 fixer for this but was shot down.
I had mentioned it during the thread where it was shot down, but I have a Google Summer of Code project (now approved and in motion - huzza!) to add confidence ranking for 2to3 fixers. As a test for the project, I'll write a fixer for string conversion and see if having a confidence value is enough to make such a fixer useful. rbp -- Rodrigo Bernardo Pimentel <rbp@isnomore.net> | GPG: <0x0DB14978>

Is there a tool available that can convert 2.x code automagically to the .format() method syntax ?
Just did a quick grep of our code base and it has some 2000 lines of code that would need to be changed.
Why do you think this code needs to change? I'd leave all the code as-is, and might not start using .format before Python 3.2, unless some coding convention says I have to. Regards, Martin

On 2008-05-10 01:18, Martin v. Löwis wrote:
Is there a tool available that can convert 2.x code automagically to the .format() method syntax ?
Just did a quick grep of our code base and it has some 2000 lines of code that would need to be changed.
Why do you think this code needs to change?
I'd leave all the code as-is, and might not start using .format before Python 3.2, unless some coding convention says I have to.
True, just wanted to know whether there is such a tool. I personally like the %-notation a lot, mainly because it's more or less the same as in C. %i, %s and %r are by far the most used format characters in our code base. Determining the position index and writing {0!s} or {0!r} instead (which requires quite a finger dance on a German keyboard) doesn't make .format() really attractive, IMHO. Perhaps you're right and it's better to wait a few rounds of refinements of .format() before jumping on that train :-) -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, May 10 2008)
Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611
participants (5)
-
"Martin v. Löwis"
-
Bill Janssen
-
M.-A. Lemburg
-
Rodrigo Bernardo Pimentel
-
skip@pobox.com