Python 3

Martin Pool mbp at canonical.com
Wed Jun 23 02:13:23 BST 2010


On 23 June 2010 11:07, Barry Warsaw <barry at canonical.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> On Jun 22, 2010, at 08:02 PM, John Arbash Meinel wrote:
>
>>I thought 2to3 doesn't actually handle that. As it expects you've
>>written python2.6 compatible code which uses:
>>
>> except locale.Error as e:
>>
>>Which we *can't* do for 2.4 or 2.5

It does actually handle this already:

--- /tmp/t.py (original)
+++ /tmp/t.py (refactored)
@@ -1,4 +1,4 @@
 try:
     pass
-except Exception, e:
-    print e
+except Exception as e:
+    print(e)
RefactoringTool: Files that need to be modified:
RefactoringTool: /tmp/t.py

If we need to make changes that either don't work under 2.[456] or
that make the code worse, and that are simple to automate, we would be
better off putting that into 2to3 than doing it once-off through a
search and replace.

-- 
Martin



More information about the bazaar mailing list