News for hackers. Stuff that matters.
Re:Automated Python 2 to 3 code translation by mherrmann on Thursday August 17, 2017 @09:12AM (#15036420)
I don't mean to be negative, but how is this better than just using the `2to3` tool that already ships with Python?
Re:Automated Python 2 to 3 code translation by mathnode on Thursday August 17, 2017 @09:29AM (#15036550)
But this web-2to3 is monetised with ads. The python community didn't think of that.
Re:Automated Python 2 to 3 code translation by raverbashing on Thursday August 17, 2017 @09:50AM (#15036725)
They (the python community) doesn't require a library for left-padding. I don't think they will fall for this
Re:Automated Python 2 to 3 code translation by mathnode on Thursday August 17, 2017 @10:37AM (#15037137)
Even the Jedi felt that burn.
Re:Automated Python 2 to 3 code translation by maweki on Thursday August 17, 2017 @09:14AM (#15036436)
That's not negative. That's the first and possibly only question.

2to3 "works" on whole projects and I'm not sending my code whoknowswhere.

Re:Automated Python 2 to 3 code translation by sajthom on Thursday August 17, 2017 @10:22AM (#15037005)
I understand this is meant as a side-project for the author to learn new stuff. From his blog: "It’s an online tool that I built for myself, and I hope other people can get some use out of it, I hav ported a lot of code in pyhon2 to python3 and I thouhgt thatthis web can help other people and also, it was a good oportunity for my, because I learned javascript and bootstrap for do it."
Re:Automated Python 2 to 3 code translation by CoffeeBob on Thursday August 17, 2017 @09:29AM (#15036548)
It's better for the people that operate the site because they get all of your Python code.
Re:Automated Python 2 to 3 code translation by raverbashing on Thursday August 17, 2017 @09:21AM (#15036489)
I guess this is a sample project, that looks like a good portfolio piece, but for real applications it has all the downsides of an online tool and none of the upsides

I'll keep calling 2to3

Re:Automated Python 2 to 3 code translation by 4c2383f5c88e911 on Thursday August 17, 2017 @09:23AM (#15036504)

  a = "test"
  if a < 1:
      print(a)
Re:Automated Python 2 to 3 code translation by tyingq on Thursday August 17, 2017 @09:47AM (#15036705)
There are some corner cases that run fine in python but trip up 2to3 tools, including this web based one. This code for example:

  print(set(x for x in range(2),))
Re:Automated Python 2 to 3 code translation by eesmith on Thursday August 17, 2017 @10:23AM (#15037016)
"asdf".encode("hex")

Is there a tool which knows to translate this to:

  import binascii
  binascii.b2a_hex(b"asdf")
Even worse, if the string isn't known to be a byte string or ASCII unicode string, it's something like:

  import binascii
  binascii.b2a_hex(s.encode("ascii") if isinstance(s, str) else s)
Re:Automated Python 2 to 3 code translation by tyingq on Thursday August 17, 2017 @11:37AM (#15037705)
Sure...that's a different thing though. Python 3's choice to introduce new types and change behavior of existing types means no automated tool can really decide what to do.

The snippet I posted is a little different in that it runs on both Python 2 as well as 3, but the 2to3 tools choke on it.

Re:Automated Python 2 to 3 code translation by eesmith on Thursday August 17, 2017 @01:36PM (#15038930)
Ahh, yes, you're right.

I'm still irritated by this specific case because my code and documentation used s.encode("hex") often, and it took a while to fix them all. Especially as the original code used both str and unicode hex-encoded values, so I couldn't drop in binascii. I ended up adding a C extension function.

Re:Automated Python 2 to 3 code translation by eesmith on Thursday August 17, 2017 @07:46PM (#15042124)
What is a 2to3 tool supposed to do here?

python2 prints "set([0, 1])" while python3 prints "{0,1}".

Is it supposed to normalize the str() so it matches Python2?

For that matter, the str() for floats has changed:

  % python
  Python 2.7.10 (default, Jul 30 2016, 19:40:32)
  [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  >>> print(-1.0000000000000002)
  -1.0
  >>>
  % python3
  Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13)
  [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  >>> print(-1.0000000000000002)
  -1.0000000000000002
Re:Automated Python 2 to 3 code translation by anc84 on Thursday August 17, 2017 @09:25AM (#15036527)
What about it?
Re:Automated Python 2 to 3 code translation by 4c2383f5c88e911 on Thursday August 17, 2017 @09:46AM (#15036696)
"test" < 1 is a TypeError in python3, and it works in python2 (returns False), it is part of the pitfalls of porting code to python 3.
Re:Automated Python 2 to 3 code translation by PerryCox on Thursday August 17, 2017 @09:28AM (#15036545)
If you enter the code above into the website it responds with:

maybe the code is wrong?

Re:Automated Python 2 to 3 code translation by anc84 on Thursday August 17, 2017 @09:33AM (#15036588)
It does not do that for me, the Python 3 version appears with no changes.