Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm surprised, if not saddened, by the low popularity of `3to2`: less than 2% of the people surveyed have used it, even though it is a convenient way to have your code in python 3 when stuck with libraries that use python 2.

edit: direct link to the pdf: https://wiki.python.org/moin/2.x-vs-3.x-survey?action=Attach...



By the time 3to2 came out, the community had already figured out that it is a better path to right code that runs under 2 and 3 rather than using conversion tools.

Conversion tools are mostly a relic of when everyone still had to support 2.5. Once you are 2.6+, most people settled on single source as the best approach.


I would presume most people who are writing 3.x code have written 2.x code before, or don't care about 2.x. I personally have gotten used to the syntax that works in both, and tend to write my code in the most compatible manner possible.


That's something for which I should strive. I've never written "polyglot" scripts longer than 1 file with 100 lines. Writing compatible syntax is feasible without too much hassle, but most problems I encountered were when I wanted to use a library whose API evolved between 2 and 3...

Do you have experience with the `six` library[0]? I've read a few times about it recently and it seems a convenient way to write portable code. I still wait for an opportunity to use it!

0: http://pythonhosted.org/six/


You can see some usage here[1]. Mostly just using it to check for string types, but it's the only usage example that I could pull off the top of my head.

[1] https://github.com/twilio/flask-restful/blob/master/flask_re...


I tried for a while to use 2to3, but found it only worked about 95% of the time, which was enough to be really annoying. Personally I'm now just using python 3 where possible, but don't fancy the pain I imagine I'd get with 3to2.

Of course, I could very well be unfairly judging 3to2, but I don't have unlimited time and spent longer than I would like trying to get 2to3 to do what I wanted.


As per results, if a lot of people are stuck with 2.x because of dependencies why would they bother with these tools?


Same reason people use Coffeescript: even if you have to run on python2, it's still nicer to develop in python3.


But nicer by enough to make it worth the bother of invoking a translator before you can run your code? Projects using Coffeescript often go out of the way to hide that step, one way or another (Rails asset pipeline, etc.). And Coffeescript arguably improves on raw JS a whole lot more than Python3 improves on Python2.


Not enough nicer to deal with any of the not-nice things that come with straddling the major version.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: