Discussion:
[ANN] Six, utilities for supporting Python 2 and 3 with the same code base
Benjamin Peterson
2010-06-29 20:57:06 UTC
Permalink
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
--
Regards,
Benjamin
Brett Cannon
2010-06-30 19:18:38 UTC
Permalink
Post by Benjamin Peterson
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.

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.

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.
Benjamin Peterson
2010-06-30 20:24:49 UTC
Permalink
Post by Brett Cannon
Post by Benjamin Peterson
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.
Post by Brett Cannon
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.
Post by Brett Cannon
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
Brett Cannon
2010-07-01 18:50:27 UTC
Permalink
Post by Benjamin Peterson
Post by Brett Cannon
Post by Benjamin Peterson
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.
Post by Brett Cannon
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).
Post by Benjamin Peterson
Post by Brett Cannon
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
Lennart Regebro
2010-06-30 20:32:49 UTC
Permalink
Post by Brett Cannon
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
Post by Brett Cannon
from bites import Bites
data = Bites(open("thefile", 'rb').read())
data.itemint(3)
75
Post by Brett Cannon
[x for x in data]
32, 45, 112, 75, 30

Otherwise you'll get characters under Python 2 and integers under Python 3.

I attached it, feel free to add it if you like.
--
Lennart Regebro: http://regebro.wordpress.com/
Python 3 Porting: http://python3porting.com/
+33 661 58 14 64
Benjamin Peterson
2010-06-30 22:13:01 UTC
Permalink
Post by Lennart Regebro
Post by Brett Cannon
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
Generally, I think the best practice here is to use slicing, but I'll
think about it.
--
Regards,
Benjamin
Lennart Regebro
2010-06-30 22:16:12 UTC
Permalink
Post by Benjamin Peterson
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
Loading...