Live data from Hacker News

Migrating to Python 3 with pleasure

github.com

131–140 of 181 posts

Re: Migrating to Python 3 with pleasure

#131

I've moved to python 3 over the past couple of months, after resisting for the better part of a decade. I like it. One surprising thing I learned from this document is that dicts now iterate in assignment order, not hash order. That's going to break some code for people.

This has been changed in Python 3.6 only, due to a change in dictionary implementation to make them more efficient. "Modern Dictionaries by Raymond Hettinger" [1] is a quite interesting and technical talk about these changes, explaining also the change in iteration order IIRC, worth a watch in my opinion!

[1] https://www.youtube.com/watch?v=p33CVV29OG8

Re: Migrating to Python 3 with pleasure

#132
post #18

Earlier quoted context omitted.

What do you mean? `A.dot(B)` and `A @ B` are the same thing for NumPy arrays. You might be mixing it up with the weirdness of `array` versus `matrix`, but that's totally separate.

The @ operator is the same as np.matmul which is different from np.dot for matrices of rank >=3.

Another difference is that B can be a scalar in the statement A.dot(B), but not in A @ B

Re: Migrating to Python 3 with pleasure

#133
post #120
post #42

Earlier quoted context omitted.

It's twice as slow, doesn't work with more than one dictionary, you can't easily control the merge prescience and you can't (easily) use expressions/variables in the keys: {**x, 'fo'+'o': 'bar', **y}

return dict(x, **{'fo'+'o': 'bar'}, **y) The new syntax is some mild syntactic sugar. (Which isn't a bad thing IMO)

Except that does not necessarily work with non-string keys (it'd depend on version and implementation IIRC).

The expanded unpacking works in all cases.

Re: Migrating to Python 3 with pleasure

#135
post #32

I've been toying around with Python 3 and using it for most of my personal/hack projects, but I somehow missed the unpacking improvements: https://www.python.org/dev/peps/pep-0448/ In particular, being able to create an updated copy of a dict with a single expression is pretty cool: return {**old, 'foo': 'bar'} # Old way new = old.copy new['foo'] = ['bar'] return new

Also: a, *b, c = range(10)

This is enlightening. So you're telling me you can do

    car, *cdr = some_list
(OMG I fired up the Python REPL and you totally can!)

Re: Migrating to Python 3 with pleasure

#136

Several posters indicate that they’ve stuck to python 2.7 even for small side projects until now. I cannot understand why? Python 3 seems to have been technically superior for a few years, and side projects must surely be good for learning something new?

I distribute python programs. Macs only have Python 2 by default.

But surely that's not stopping anyone. As someone above said, just use pyenv to run Python 2.7x and Python 3. It's not as if anyone has to settle for using only legacy Python.

Re: Migrating to Python 3 with pleasure

#137
post #69
post #65

I had so many issues trying to install python3 in an existing server that I ended up having to go back. pip kept complaining and it was just really annoying. Then some libraries were not compatible and it felt like it wasn't worth it.

Isn't python 3 usually installed alongside python/pip 2.7 as python3/pip3, and everything kept seperately?

If you use pyenv, it is.

Re: Migrating to Python 3 with pleasure

#138

I’m a little surprised at this point that Apple still doesn’t include a default Python 3.x on macOS. It’s the single thing keeping me from moving (as there’s a big difference between “just run this” and “first download this, then run this”).

My theory is that this is not going to be a nice change when they drop 2.7. Maybe one version will be released with both installed by default, then they'll use only 3.7/3.8 for the next decade. MacOS doesn't seem to care a lot about backwards compatibility recently.

This is of course pure speculation...

Re: Migrating to Python 3 with pleasure

#139

I’m a little surprised at this point that Apple still doesn’t include a default Python 3.x on macOS. It’s the single thing keeping me from moving (as there’s a big difference between “just run this” and “first download this, then run this”).

Honestly the fact that they include a system Python 2 is a huge pain. You can't add packages to it, and you shouldn't add another Python 2 interpreter to the PATH. You end up having to use virtualenv which is a stupid hack.

Re: Migrating to Python 3 with pleasure

#140

Type hinting isn't part of Python 3, it's part of Python 3.5+.

Syntactic support for annotating functions and exposing the annotations existed as of 3.0. The 'typing' module in the standard library was new as of 3.5. Syntactic support for annotating variables was new as of 3.6. Support for delaying resolution of annotations is new in 3.7 with a __future__ import. Originally the annotation feature was seen as a possible way to add type hints to Python, but other potential uses we…

With type comments you can use it in 2.7 as well: https://www.python.org/dev/peps/pep-0484/#suggested-syntax-f...

Mypy supports it: http://mypy.readthedocs.io/en/latest/python2.html

Post reply on HN