[Python-ideas] add a single __future__ for py3?
Luciano Ramalho
luciano at ramalho.org
Sun Sep 20 15:59:54 CEST 2015
Chris,
I don't think students should be worrying about writing code that is
Python 2 and Python 3 compatible.
That's a concern only for people who write libraries, tools and
frameworks for others to use, and I do not think these are the kinds
of programs students usually do. Even if they are doing something
along those lines, they should be focusing on other more important
features of the programs rather than whether they run on Python 2 and
on Python 3.
Having said that, I'd also like to add that I don't think ``from
__future__ import unicode_literals`` is a great idea for making code
2/3 compatible nowadays. It was necessary before the u'' prefix was
reinstated in Python 3.3, but since u'' is back it's much better to be
explicit in your literals rather than dealing with runtime errors
because of the blanket effect of the unicode_literals import.
Anyone who cares about 2/3 compatibility should mark every single
literal with a u'' or a b'' prefix.
But students should not be distracted by this. They should be using
Python 3 only ;-).
Cheers,
Luciano
On Sat, Sep 19, 2015 at 3:41 PM, Sven R. Kunze <srkunze at mail.de> wrote:
> I totally agree here.
>
>
> On 19.09.2015 19:50, Chris Barker wrote:
>
> Hi all,
>
> the common advise, these days, if you want to write py2/3 compatible code,
> is to do:
>
> from __future__ import absolute_import
> from __future__ import division
> from __future__ import print_function
> from __future__ import unicode_literals
>
> https://docs.python.org/2/howto/pyporting.html#prevent-compatibility-regressions
>
> I'm trying to do this in my code, and teaching my students to do it to.
>
> but that's actually a lot of code to write.
>
> It would be nice to have a:
>
> from __future__ import py3
>
> or something like that, that would do all of those in one swipe.
>
> IIIC, l can't make a little module that does that, because the __future__
> imports only effect the module in which they are imported
>
> Sure, it's not a huge deal, but it would make it easier for folks wanting to
> keep up this best practice.
>
> Of course, this wouldn't happen until 2.7.11, if an when there even is one,
> but it would be nice to get it on the list....
>
> -Chris
>
>
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R (206) 526-6959 voice
> 7600 Sand Point Way NE (206) 526-6329 fax
> Seattle, WA 98115 (206) 526-6317 main reception
>
> Chris.Barker at noaa.gov
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
--
Luciano Ramalho
| Author of Fluent Python (O'Reilly, 2015)
| http://shop.oreilly.com/product/0636920032519.do
| Professor em: http://python.pro.br
| Twitter: @ramalhoorg
More information about the Python-ideas
mailing list