Live data from Hacker News

Migrating to Python 3 with pleasure

github.com

61–70 of 181 posts

Re: Migrating to Python 3 with pleasure

#61
post #47

Is there some kind of slash operator making this statement work? Is this a way to concatenate things? train_path = datasets_root / dataset / 'train'

Python allows the overriding of just about every operator. For Pathlib they overrode the division operator to instead perform path addition in a platform agnostic manner.

> Python allows the overriding of just about every operator.

Except the boolean operators (and, or, not). For instance __and__ overrides the binary and (&), not the boolean and.

Re: Migrating to Python 3 with pleasure

#62
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”).

Re: Migrating to Python 3 with pleasure

#63
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 scripts to the few servers we have that are still running RHEL 6).

Re: Migrating to Python 3 with pleasure

#64

Earlier quoted context omitted.

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

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…

> 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.

Here's one real-life use case of that: Avro records. One of the formats Avro uses is a text format that's basically ordered JSON. One company I worked for years ago used Avro as its wire protocol, and some Avro data was stored as JSON files on disk. Of course, Python's JSON implementation by default loads/unloads JSON to/from a dict. So just calling json.load() and json.dump() means I can't just load an Avro record from disk, change some data, and save it (which is something that came up when I was writing an upgrade script at a company I was working at years ago).

Thankfully, I had an out: the JSON library lets you override what container you load JSON into with object_pairs_hook, so I could just snarf it into an OrderedDict. But if I ever have to do this again after 3.7 comes out, I'm glad I won't have to worry about making sure I have the right container class. It makes my code simpler, and I won't have to leave a comment explaining why the code will break unless I specify an OrderedDict.

Re: Migrating to Python 3 with pleasure

#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.

Re: Migrating to Python 3 with pleasure

#66

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”).

Downloading it is definitely not the biggest hurdle to moving to python 3.

Re: Migrating to Python 3 with pleasure

#68
post #55
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}

why wouldn't you be able to just keep the same syntax and make it twice as fast in a newer implementation?

NIH.

Personally I hate the new {} for set syntax.

Is {} an empty set, or an empty dict?

Re: Migrating to Python 3 with pleasure

#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?

Re: Migrating to Python 3 with pleasure

#70

Earlier quoted context omitted.

Not the result set, the rows of the result set.

Unless there is an "order by" clause, the order of rows in the result set is undefined and non-deterministic from query to query.

As I said:

> Not the result set, the rows of the result set.

Each row is a mapping with ordered keys.

Post reply on HN