From benjamin at python.org Thu Jul 1 00:13:01 2010 From: benjamin at python.org (Benjamin Peterson) Date: Wed, 30 Jun 2010 17:13:01 -0500 Subject: [Python-porting] [ANN] Six, utilities for supporting Python 2 and 3 with the same code base In-Reply-To: References: Message-ID: 2010/6/30 Lennart Regebro : > On Wed, Jun 30, 2010 at 21:18, Brett Cannon wrote: >> I was actually thinking about doing this; you beat me to it! =) > > Me three! :-) > > I haven't looked at the code yet, just the docs. I have a suggestion > for an addition, my bites-class. It's a subclass for bytes or str > (depending on Python version) that enables you to do slicing of binary > data with the same API both under Python 2 and Python 3. Like so: Generally, I think the best practice here is to use slicing, but I'll think about it. -- Regards, Benjamin From regebro at gmail.com Thu Jul 1 00:16:12 2010 From: regebro at gmail.com (Lennart Regebro) Date: Thu, 1 Jul 2010 00:16:12 +0200 Subject: [Python-porting] [ANN] Six, utilities for supporting Python 2 and 3 with the same code base In-Reply-To: References: Message-ID: On Thu, Jul 1, 2010 at 00:13, Benjamin Peterson wrote: > Generally, I think the best practice here is to use slicing, but I'll > think about it. Yes, slicing together with your b() function solves 99% of the cases, absolutely. This is just for the remaining, cases, I'm not sure how often you actually would need these bites classes. It's quite specialized. :) -- Lennart Regebro: http://regebro.wordpress.com/ Python 3 Porting: http://python3porting.com/ +33 661 58 14 64 From brett at python.org Thu Jul 1 20:50:27 2010 From: brett at python.org (Brett Cannon) Date: Thu, 1 Jul 2010 11:50:27 -0700 Subject: [Python-porting] [ANN] Six, utilities for supporting Python 2 and 3 with the same code base In-Reply-To: References: Message-ID: On Wed, Jun 30, 2010 at 13:24, Benjamin Peterson wrote: > 2010/6/30 Brett Cannon : >> On Tue, Jun 29, 2010 at 13:57, Benjamin Peterson wrote: >>> I've just released for the first time six, a set of helpers for >>> maintaining a code base on Python 2 and 3 simultaneously. It includes >>> fake byte and unicode literals and wrappers for syntax changes between >>> the languages. The license is MIT. >>> >>> You can download it on PyPi: http://pypi.python.org/pypi/six >>> or read the documentation: http://packages.python.org/six/ >>> >>> Bugs can be reported to the Launchpad page: http://bugs.launchpad.net/python-six >> >> I was actually thinking about doing this; you beat me to it! =) >> >> Looks good overall. Only three suggestions. One is that the >> documentation for const is a little confusing; I would move the >> example to the end as I thought that dispatch_types was an actual >> function in the module instead of just example usage. > > Moved, thank you. > >> >> Two, is there a need for a function to get the currently raised >> exception (especially without the traceback to prevent accidental >> circular loops)? Since that part of the syntax changed it would >> probably be good to have a function to call which returns the raised >> exception. Don't remember if the 'with' statement cleans up its >> variables, but if it does then the traceback object could be exposed >> on a context manager w/o leaking. > > I believe sys.exc_info()[:2] is still the correct way in both Python versions. It is, I just don't know how widely known the idiom is. Maybe just a mention in the documentation? Or better yet, hope the PSF gets me that grant money so I can write a HOWTO on all of this and just mention it myself (along with 'six' of course). > >> >> And lastly, a link back to the PyPI page from the packages.python.org >> pages would be good in case the docs end up ranking higher in searches >> than the PyPI page. > > Done. > > > > -- > Regards, > Benjamin >