Questions tagged [python-3.8]

This tag is for issues that are specific to Python 3.8. For general questions use the more generic [python] and [python-3.x] tags.

Python 3.8 was released on 2019-10-14 (PEP 569).


Use this tag if your question is specifically related to Python 3.8. Otherwise, use the following guidelines to determine which tag(s) you should add to your question:

  • If your question applies to Python in general, use only the tag.
  • If your question applies to Python 3.x but not to Python 2.x, add the tag .
  • If you aren't sure, tag your question with and mention which version you're using in the post.

References

1757 questions
69
votes
3 answers

":=" syntax and assignment expressions: what and why?

PEP 572 introduces assignment expressions (colloquially known as the Walrus Operator), implemented for Python 3.8. This seems like a really substantial new feature since it will allow this form of assignment within comprehensions and lambda…
63
votes
10 answers

AttributeError: module 'time' has no attribute 'clock' in Python 3.8

I have written code to generate public and private keys. It works great at Python 3.7 but it fails in Python 3.8. I don't know how it fails in the latest version. Help me with some solutions. Here's the Code: from Crypto.PublicKey import RSA def…
user11576444
52
votes
3 answers

Why is math.sqrt massively slower than exponentiation?

I can't believe what I just measured: python3 -m timeit -s "from math import sqrt" "sqrt(2)" 5000000 loops, best of 5: 42.8 nsec per loop python3 -m timeit "2 ** 0.5" 50000000 loops, best of 5: 4.93 nsec per loop This goes against any intuition...…
Peter Leikauf
  • 545
  • 2
  • 6
33
votes
5 answers

How to fix "module 'platform' has no attribute 'linux_distribution'" when installing new packages with Python3.8?

I had Python versions of 2.7 and 3.5. I wanted the install a newer version of Python which is python 3.8. I am using Ubuntu 16.04 and I can not just uninstall Python 3.5 due to the dependencies. So in order to run my scripts, I use python3.8 app.py.…
EmreAkkoc
  • 500
  • 1
  • 7
  • 17
27
votes
1 answer

With assignment expressions in Python 3.8, why do we need to use `as` in `with`?

Now that PEP 572 has been accepted, Python 3.8 is destined to have assignment expressions, so we can use an assignment expression in with, i.e. with (f := open('file.txt')): for l in f: print(f) instead of with open('file.txt') as f: …
Antti Haapala
  • 117,318
  • 21
  • 243
  • 279
27
votes
4 answers

Is it possible to add a where clause with list comprehension?

Consider the following list comprehension [ (x,f(x)) for x in iterable if f(x) ] This filters the iterable based a condition f and returns the pairs of x,f(x). The problem with this approach is f(x) is calculated twice. It would be great if we…
17
votes
3 answers

How to downgrade python version from 3.8 to 3.7 (mac)

I'm using Python & okta-aws tools and in order to fetch correct credentials on aws I need to run okta-aws init. But got an error message of Could not read roles from Okta and the system prompted that"Your Pipfile requires python_version 3.7, but you…
user13902742
  • 213
  • 1
  • 1
  • 5
17
votes
3 answers

Install Python 3.8 kernel in Google Colaboratory

I try to install a new Python version (3.8) using conda. !wget -O mini.sh https://repo.anaconda.com/miniconda/Miniconda3-py38_4.8.2-Linux-x86_64.sh !chmod +x mini.sh !bash ./mini.sh -b -f -p /usr/local This works fine. I can call !python script.py…
korakot
  • 24,489
  • 13
  • 84
  • 114
16
votes
4 answers

What does = (equal) do in f-strings inside the expression curly brackets?

The usage of {} in Python f-strings is well known to execute pieces of code and give the result in string format (some tutorials here). However, what does the '=' at the end of the expression mean? log_file = open("log_aug_19.txt", "w")…
ibarrond
  • 3,987
  • 1
  • 14
  • 33
15
votes
2 answers

ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/__init__.py)

I installed pip3 using sudo apt-get install python3-pip after that when I run the following command to install django sudo pip3 install django I get this error: Traceback (most recent call last): File "/usr/bin/pip3", line 9, in from pip import…
Leman Kirme
  • 314
  • 3
  • 11
15
votes
1 answer

pycharm does not connect to console with python3.8

I dont know why; but since python 3.8 has been released; I cant run pycharm console and it is always in the "being connected" status. I have had no problem with python 3.7; since the console is opened immediately. Here you can see that I have tried…
moh80s
  • 695
  • 4
  • 21
15
votes
5 answers

How to deal with Kivy installing error in Python 3.8?

I have installed every necessary code in Python from Kivy, but the last one I need which one is python -m pip install kivy gets me an error like this: ERROR: Dependency for context.pyx not resolved: config.pxi ERROR: Dependency for compiler.pyx not…
Atis
  • 151
  • 1
  • 1
  • 5
13
votes
1 answer

How do Assignment Expressions `:=` work in Python?

I've read PEP 572 about assignment expressions and I found this code to be a clear example where I could use it: while line := fp.readline(): do_stuff(line) But I am confused, from what I read, it is supposed to work just like normal assignment…
Benoît P
  • 2,684
  • 9
  • 30
12
votes
2 answers

Why can't Python's walrus operator be used to set instance attributes?

I just learned that the new walrus operator (:=) can't be used to set instance attributes, it's supposedly invalid syntax (raises a SyntaxError). Why is this? (And can you provide a link to official docs mentioning this?) I looked through PEP 572,…
11
votes
2 answers

`super` in a `typing.NamedTuple` subclass fails in python 3.8

I have code which worked in Python 3.6 and fails in Python 3.8. It seems to boil down to calling super in subclass of typing.NamedTuple, as below: in ----> 1 class Test(typing.NamedTuple): 2 a: int …
Jatentaki
  • 8,339
  • 2
  • 33
  • 32
1
2 3
99 100