Live data from Hacker News

What's Coming in Python 3.8

lwn.net

241–250 of 558 posts

Re: What's Coming in Python 3.8

#241
post #62

Earlier quoted context omitted.

I see what you're saying, but I kinda like the gets ":=" operator.

But now there are two ways to do assignment. That's not very pythonic, is it?

I never felt like there was only one way to do something in Python. Every Stack Overflow question has a multitude of answers ranging from imperative to functional style and with various benefits and drawbacks.

Python is one of the least "only one way to do things" languages I've used. This even extends to its packaging system, where you can choose between virtualenv, pipenv, pyenv, etc. Same goes for the installation method too, do you want to install Python with Anaconda or use the default method?

As for my personal take on this feature: I think it's really useful. When web-scraping in Python, I oftentimes had to do this:

  while True:
      html_element = scrape_element()
      if html_element:
          break
      sleep(10)
Now I can do this:

  while not html_element := scrape_element():
      sleep(10)

Re: What's Coming in Python 3.8

#242
post #238
post #118

Despite controversy, walrus operator is going to be like f-strings. Before: "Why do we need another way to..." After: "Hey this is great". People are wtf-ing a bit about the positional-only parameters, but I view that as just a consistency change. It's a way to write in pure Python something that was previously only possible to say using the C api.

I wonder if the controversial Go's error check function "try" proposal[0] will also be similar to this situation. [0]: https://github.com/golang/go/issues/32437

That was already cancelled.

Re: What's Coming in Python 3.8

#243

Earlier quoted context omitted.

Was the controversy really about the need for the feature? I thought most people agreed it was a great feature to have, and most of the arguments were about `:=` vs re-using `as` for the operator.

I don't know in this case, but I do know that the Python community tends to have strong opinions about things. The := resulted in Guido stepping down, which I think is a good indicator that there wasn't agreement that it was "a great feature to have" and just down to syntax... :-(

To be fair, Guido stepped down because of the way the community reacted.

"The straw that broke the camel’s back was a very contentious Python enhancement proposal, where after I had accepted it, people went to social media like Twitter and said things that really hurt me personally. And some of the people who said hurtful things were actually core Python developers, so I felt that I didn’t quite have the trust of the Python core developer team anymore."

Source: https://www.infoworld.com/article/3292936/guido-van-rossum-r...

Note that Guido also was in support of the walrus operator, it's not like he stepped down because he disagreed with it.

Re: What's Coming in Python 3.8

#244
post #166

How come they are using a new := operator instead of using equals?

That's literally the point: it's not the assignment operator.

The difference between = and == in an if causes many hugs in other languages. Using := for assignment in an expression instead of == means that you can't simply have a typo and have a bug.

Re: What's Coming in Python 3.8

#245
post #118

Despite controversy, walrus operator is going to be like f-strings. Before: "Why do we need another way to..." After: "Hey this is great". People are wtf-ing a bit about the positional-only parameters, but I view that as just a consistency change. It's a way to write in pure Python something that was previously only possible to say using the C api.

Was the controversy really about the need for the feature? I thought most people agreed it was a great feature to have, and most of the arguments were about `:=` vs re-using `as` for the operator.

I like "as" instead. I didn't realize that was on the table. To me, it seems more Pythonic given the typical English-like Python syntax of "with open(path) as file", "for element in items if element not in things", etc.

Re: What's Coming in Python 3.8

#246
post #24
post #8

Python looks more and more foreign with each release. I'm not sure what happened after 3.3 but it seems like the whole philosophy of "pythonic", emphasizing simplicity, readability and "only one straightforward way to do it" is rapidly disappearing.

“I've come up with a set of rules that describe our reactions to technologies: 1. Anything that is in the world when you’re born is normal and ordinary and is just a natural part of the way the world works. 2. Anything that's invented between when you’re fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. 3. Anything invented after you're thirty-five is against the n…

I am an example which supports this notion. I've done some Python programming about 10 years ago but then took a break from programming altogether for the last 9 years. Last year I got back into it and have been using Python 3.7, and I personally love all the most recent stuff. I hate having to go back to 3.5 or even 3.6, and I end up pulling in stuff from futures.

Re: What's Coming in Python 3.8

#247
post #25

Earlier quoted context omitted.

F-strings have appeared 2 versions ago. All in all, the feedback we have has been overwhelmingly positive, including on maintenance and readability.

I love f-strings. I just wish tools like pylint would shut up when I pass f-strings to the logging module. I as the developer understand and accept the extra nanosecond of processor time to parse the string that might not be logged anywhere!

It's not just performance!

Using percent formatting is superior in many ways:

- errors that occur in formatting a message will be logged instead of raising an exception into your application

- error reporting services like Sentry can properly aggregate events

- interpolation won't occur if you don't have the logging level enabled

- it's recommend by the Python docs: https://docs.python.org/3/howto/logging-cookbook.html#use-of...

Re: What's Coming in Python 3.8

#248

Does it make sense to use := everywhere (can it be used everywhere?) instead of just in conditionals? Just like Pascal.

About as much sense as it makes to use ; after every Python statement. Just like Pascal.

(Yeah I know, ; is a statement separator, not a statement terminator in Pascal.)

As long as you're being just like Pascal, did you know Python supported Pascal-like "BEGIN" and "END" statements? You just have to prefix them with the "#" character (and indent the code inside them correctly, of course). ;)

    if x 

Re: What's Coming in Python 3.8

#249
post #62

Earlier quoted context omitted.

But now there are two ways to do assignment. That's not very pythonic, is it?

You think that's bad? Check out: a = 17 print("a=", a) print("a=" + str(a)) print("a=%s" % a) print("a={}".format(a)) print(f"a={a}") # python 3.8 => print(f"{a=}") So many ways to do it... But, if it sounds like I agree with you, I actually don't. I feel that the Zen of Python has taken on an almost religious level of veneration in people's minds, and leads to all sorts of unproductive debates. One person can latch…

And there was also:

    print string.Template("a=$a").substitute(a=a)

Re: What's Coming in Python 3.8

#250

Earlier quoted context omitted.

This is why a lot of scientific code still uses fortran, code written several decades ago still compiles and has the same output. How long has the code which was transitioned to python lasted?

> How long has the code which was transitioned to python lasted? A long time. 2to3 was good for ~90% of my code, at least

Good for 90% of your code is not equivalent to getting precisely the same results from unmodified code written in the 80s.
Post reply on HN