I'd been a 2.7 holdout for ages, but when f-strings were greenlit for 3.6, I decided then and there that all my new personal projects would be written in 3. I'm glad I did. F-strings are wonderful, as is pathlib and the enhanced unpacking syntax. Since I started my current job, I've also been writing as many scripts as I can in Python 3 as well (and Docker has been a godsend for that because I can now deploy 3.6 scri…
Migrating to Python 3 with pleasure
81–90 of 181 posts
Re: Migrating to Python 3 with pleasure
#82I’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”).
Downloading it is definitely not the biggest hurdle to moving to python 3.
Re: Migrating to Python 3 with pleasure
#83Earlier quoted context omitted.
Not for much longer, as of 3.7 the ordering is a language feature: https://mail.python.org/pipermail/python-dev/2017-December/1... It's mad that it ever wasn't this way. Mapping-with-ordered-keys is such a useful and pervasive data structure (all database query result rows, for one) that an ordered dictionary should be a fundamental part of a language. It has been so much more pleasant to write python since ordering…
I have the opposite reaction to it, it seems insanely idiotic to have a associative array with ordered keys. It can only make sense to someone who doesn't know anything about fundamental data structures and a language that caters to people like that in spite of the performance penalty is just strange. but hey, its Guido, I still can't fathom that he moved reduce into functools.
Re: Migrating to Python 3 with pleasure
#84I'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
Re: Migrating to Python 3 with pleasure
#85Earlier quoted context omitted.
return {**old, 'foo': 'bar'} # Old way return dict(old, foo='bar') Not much difference if you ask me.
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}
X ++ {'fo'+'o': 'bar'} ++ y
Where '++' here means dictionary union, the choice of symbol is not relevant.
Re: Migrating to Python 3 with pleasure
#86I'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.
Dicts are UNORDERED associative containers. If youre depending your app on implementation defined behavior, that's on your developpers shoulders. Stuff like that shouldn't pass code review
Srsly look at js.. How many bugs and fast first solutions are syntactic sugar by now.. Its just temp O' Rary until sth better comes along always becomes the default behavior.
Re: Migrating to Python 3 with pleasure
#87I'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.
Dicts are UNORDERED associative containers. If youre depending your app on implementation defined behavior, that's on your developpers shoulders. Stuff like that shouldn't pass code review
aside from that, python has a separate ordered dict class
Re: Migrating to Python 3 with pleasure
#88Earlier 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}
why wouldn't you be able to just keep the same syntax and make it twice as fast in a newer implementation?
Re: Migrating to Python 3 with pleasure
#89I'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
This is a lot like JavaScript :)
Re: Migrating to Python 3 with pleasure
#90I’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”).