Live data from Hacker News

New features you can't use unless you are in Python 3

asmeurer.com

101–110 of 264 posts

Re: New features you can't use unless you are in Python 3

#101
post #40

Earlier quoted context omitted.

It was source-level incompatible with older code so it couldn't be used as a smooth transition like... almost any other language upgrade I've ever seen. Breaking code like this was a big mistake in my opinion - it resulted in many people sticking on the old version for code and library compatibility. There are still libraries which don't work on Python 3, though now fairly few of them. In addition to that, the unicod…

Most Python 2 codebases probably have a lot of unknown bugs in them related to Unicode. The code will work fine for cases where the inputs are ASCII, but will subtly break if unicode inputs are provided. In term's of code reliability, Python 3's approach is much more sane.

And if Python simply used utf-8 everywhere, those ASCII expecting code would continue to work fine when unicode inputs are provided.

Re: New features you can't use unless you are in Python 3

#102

From: http://www.asmeurer.com/python3-presentation/slides.html#55 ... why is this good: def dup(n): for i in range(n): yield i yield i ... but this one better? def dup(n): for i in range(n): yield from [i, i] ... it would seem you're needlessly creating (1): another level of generators, and (2) creating a real list

Yeah at the very least this should be a tuple rather than a list:

      yield from (i, i)
It does use fewer lines, but if that's the point then this would work:

      yield i; yield i

Re: New features you can't use unless you are in Python 3

#103
post #66

I did not know you could append to a Path via "/", but that's really awesome! I also really love working with generators when I write Python. They are just such a simple idea that's very powerful and I miss them so much when I go back to javascript (I know javascript has them now, but I haven't written them, and they don't look as fluent as Python 3, where the large parts of the language design is based around them).

can't say I'm thrilled about this sugar (override division operator in another context).

Re: New features you can't use unless you are in Python 3

#104
post #66

I did not know you could append to a Path via "/", but that's really awesome! I also really love working with generators when I write Python. They are just such a simple idea that's very powerful and I miss them so much when I go back to javascript (I know javascript has them now, but I haven't written them, and they don't look as fluent as Python 3, where the large parts of the language design is based around them).

Overloading operators for cute purposes is usually a misfeature. There was a fad for this in the early C++ days. I once wrote a marshalling library which overloaded "||", so that you could write

    p = stream || rec.a || rec.b || rec.c;
and get an object which, if written, marshalled the record, and if read, unmarshalled it. The marshalling order was only specified once. Cute, but in retrospect, bad.

Python's classic overload problem comes from using "+" for concatenate. For built-in vectors, "+" is concatenate, but for NumPy arrays, it's addition. You can use "+" between a NumPy array and a built-in vector. Does it add, or concatenate?

("|" is supposed to be the concatenate operator; it was added to ASCII to support PL/I. But decades of C have made it the bitwise OR operator to most programmers, so we're stuck. "_" is allowed within symbols, so that's taken. There's "⁀", character tie, but nobody can type it.)

It seems to be best to restrict the math operators to math.

Re: New features you can't use unless you are in Python 3

#105
post #92

Earlier quoted context omitted.

I haven't figured out the proper incantations to install matplotlib on python 3.x on OSX. So I stick with 2.7.

> conda install matplotlib Anaconda Python really should be more popular on OS X and Linux than it is. Homebrew is okay, but a little bit wonky for Python packages.

Thanks for the suggestion. I've briefly tried Anaconda before, unfortunately can't remember why I didn't continue with it.

I just tried again and saw an error similar to what I get when I try with pip+brew - ModuleNotFoundError: No module named 'PyQt4'.

Note, this is after spending quite a while installing/removing/upgrading various qt packages and dependencies to try to resolve this. The system might be in a weird state because of that - but I originally started from scratch and only followed the instructions I found on the matplotlib site...

Re: New features you can't use unless you are in Python 3

#106
One big thing that's missing from this list is the __traceback__ on exceptions, which pretty much does what you think it does. In Python 2, there's no way to access the traceback for an exception once you've left the `except:` block. This matters when you're using things like gevent; if one of your gevent greenlets throws an exception and you inspect the .exception attribute on it, you'll be able to get the exception message but won't know what line it came from.

N.B. This is absent from Python 2 due to concerns with creating self-referential loops. The garbage collector got better in the meantime and the feature was never backported to Python 2.

Re: New features you can't use unless you are in Python 3

#107
post #94

Earlier quoted context omitted.

I haven't figured out the proper incantations to install matplotlib on python 3.x on OSX. So I stick with 2.7.

Have you tried installing anaconda?

Yes: https://news.ycombinator.com/item?id=14555206

Re: New features you can't use unless you are in Python 3

#108

From: http://www.asmeurer.com/python3-presentation/slides.html#55 ... why is this good: def dup(n): for i in range(n): yield i yield i ... but this one better? def dup(n): for i in range(n): yield from [i, i] ... it would seem you're needlessly creating (1): another level of generators, and (2) creating a real list

I think for that example it doesn't matter, it is a poor illustration of yield from.

In general `yield from` makes delegation inside a generator cleaner.

Re: New features you can't use unless you are in Python 3

#109

From: http://www.asmeurer.com/python3-presentation/slides.html#55 ... why is this good: def dup(n): for i in range(n): yield i yield i ... but this one better? def dup(n): for i in range(n): yield from [i, i] ... it would seem you're needlessly creating (1): another level of generators, and (2) creating a real list

Compare these instead:

for i in range(n): yield i

yield from range(n)

Re: New features you can't use unless you are in Python 3

#110
post #23
post #12

Earlier quoted context omitted.

Using the arrows keys for the slides has been a standard since the dawn of web presentations, a decade or so ago. Doesn't have to be more discoverable imho. As soon one finds it out, they can use the knowledge for any other presentation they chance upon -- and presentations remain clutter free, without prompts and extra navigational buttons for the rest.

> Using the arrows keys for the slides has been a standard since the dawn of web presentations, a decade or so ago. So have arrows icons you can click to switch slides... Such as on Slideshare (coincidentally a decade old!).

If the icons disappear as soon as I use my keyboard or tap, that wouldn't be too terrible.
Post reply on HN