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.
Migrating to Python 3 with pleasure
131–140 of 181 posts
Re: Migrating to Python 3 with pleasure
#132Earlier 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.
Re: Migrating to Python 3 with pleasure
#133Earlier 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)
The expanded unpacking works in all cases.
Re: Migrating to Python 3 with pleasure
#134Re: Migrating to Python 3 with pleasure
#135I'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)
car, *cdr = some_list
(OMG I fired up the Python REPL and you totally can!)Re: Migrating to Python 3 with pleasure
#136Several 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.
Re: Migrating to Python 3 with pleasure
#137I 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?
Re: Migrating to Python 3 with pleasure
#138I’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”).
This is of course pure speculation...
Re: Migrating to Python 3 with pleasure
#139I’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”).
Re: Migrating to Python 3 with pleasure
#140Type 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…
Mypy supports it: http://mypy.readthedocs.io/en/latest/python2.html