Live data from Hacker News

Migrating to Python 3 with pleasure

github.com

121–130 of 181 posts

Re: Migrating to Python 3 with pleasure

#121

Earlier quoted context omitted.

It was recently decided that as of 3.7 it will be. (Source: https://mail.python.org/pipermail/python-dev/2017-December/1... )

Hmmmmmm.... that makes it hard for other implementations. CPython isn't the whole of the Python world. Requirements like that can be problematic for implementations like Micropython, for instance.

The headache that having non-deterministic code causes more than makes up for that.

Among other things this makes writing tests much easier.

Re: Migrating to Python 3 with pleasure

#122
post #109

Earlier quoted context omitted.

And the multiprocessing and threading pools. And collections.ChainMap. And f-strings. And yield from. And type hints. And statistics. And ipadress. And secrets. And matmul. And subprocess.run. Come on, Python 3 is packed with awesomeness !

Every time somebody mentions how awsome f-strings are makes me laugh. It was around ten years ago when Python community was looking down at Perl and shell with their string interpolation, but now that Python got pretty much the same it's suddenly not considered a misfeature.

Have you considered that maybe the language had not evolved enough for them to be appealing. With b'' and u'' string syntax coming into the language, there is a realisation that string interpolation can be an opt-in feature among other reasons.

What you have is decision making analogous to the function

    evaluate(string_interpolation, python_ecosystem)
which is different from

    evaluate(string_interpolation)

Re: Migrating to Python 3 with pleasure

#123

Earlier quoted context omitted.

A section called "CPython implementation detail" looks like the very antithesis of a guarantee, to me.

My apologies. I looked for the answer I knew was there, and quoted the wrong section because it matched what I was looking for. I should have quoted the next section: > If items(), keys(), values(), iteritems(), iterkeys(), and itervalues() are called with no intervening modifications to the dictionary, the lists will directly correspond. Curiously, the "Dictionary view objects" section at https://docs.python.org/2.7…

Huh, that's inconsistent. I guess they changed it to avoid the security problem and forgot to change the docs? Or maybe they didn't update 2.7 at all and it still behaves that way.

Re: Migrating to Python 3 with pleasure

#124
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)

On the face of it, sure, but really it's some new bytecode that gets rid of the limitations of using kwargs like that, namely it's slow, impossible to really optimize and doesn't support duplicate keys.

Re: Migrating to Python 3 with pleasure

#125
post #39
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

return {**old, 'foo': 'bar'} # Old way return dict(old, foo='bar') Not much difference if you ask me.

I'm allergic to the { ... } thing. And I like terse and cryptic, but for some reason I find it the less attractive syntactical trick of all python3 (that I know).

dict(a, ... ,b) feels cleaner.

Re: Migrating to Python 3 with pleasure

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

My mind is blown. Ever since JavaScript added this, I've been wanting it in Python... and somehow it was there all along. It works for lists too! [*a, *b, *c]

bear in mind that most things javascript got recently are old. literals, closure syntax, destruct, spread .. (lisp, scheme of course, but yeah python took it a while back too) this is all very very old but now ECMAxxxx is bringing it to the mainstream.

Re: Migrating to Python 3 with pleasure

#128
post #85
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}

Surely a more intuitive syntax would be: X ++ {'fo'+'o': 'bar'} ++ y Where '++' here means dictionary union, the choice of symbol is not relevant.

Not really, and it's not getting most pythonic way of doing things IMO. With the syntax above (I think) you can work with any iterable, whereas with a dictionary union operator you'd have to define it on every class you'd want to use, and you'd be out of luck with generators.

Re: Migrating to Python 3 with pleasure

#129
post #9

Earlier quoted context omitted.

Dicts never had an iteration order, though. If you relied on dicts iterating in order, you were kind of asking for it.

I believe newer Python versions have at least deterministic iteration order (correct me if I'm wrong), while some previous ones had a non-deterministic one (non-deterministic between mutiple invocations of the interpreter). But there is also OrderedDict which iterates in assignment order.

In 3.6 dicts are ordered (by insert order) as an implementation detail. From 3.7 on it will be a feature.

Re: Migrating to Python 3 with pleasure

#130
post #4

Earlier quoted context omitted.

Wow, I switched to Python 3 really early on and never knew about pathlib.

And the multiprocessing and threading pools. And collections.ChainMap. And f-strings. And yield from. And type hints. And statistics. And ipadress. And secrets. And matmul. And subprocess.run. Come on, Python 3 is packed with awesomeness !

multiprocessing and threading pools

While certainly awesome, these are in python 2.7 as well. Although I don't remember if they where in 2.7 first of back-ported to 2.7 from 3.

Post reply on HN