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

2332 questions
120
votes
16 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
100
votes
6 answers

What are assignment expressions (using the "walrus" or ":=" operator)? Why was this syntax added?

Since Python 3.8, code can use the so-called "walrus" operator (:=), documented in PEP 572, for assignment expressions. This seems like a really substantial new feature, since it allows this form of assignment within comprehensions and lambdas. What…
Chris_Rands
  • 38,994
  • 14
  • 83
  • 119
62
votes
5 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
  • 6,617
  • 4
  • 26
  • 45
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
  • 3
  • 6
46
votes
4 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
  • 505
  • 1
  • 4
  • 6
45
votes
7 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
  • 623
  • 1
  • 11
  • 18
43
votes
8 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
  • 37,818
  • 16
  • 123
  • 144
33
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
  • 530
  • 1
  • 5
  • 19
30
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…
29
votes
2 answers

Getting the literal out of a python Literal type, at runtime?

How can I get the literal value out of a Literal[] from typing? from typing import Literal, Union Add = Literal['add'] Multiply = Literal['mul'] Action = Union[Add,Multiply] def do(a: Action): if a == Add: print("Adding!") elif a…
LudvigH
  • 3,662
  • 5
  • 31
  • 49
28
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: …
24
votes
5 answers

Top level object in './docker-compose.yml' needs to be an object not ''

I'm using python 3.8, Docker version 19.03.13, build 4484c46d9d 3.8 version: '3.8' services: web: build: . command: python /code/manage.py runserver 0.0.0.0:8000 volumes: - .:/code ports: - 8000:8000
Hesham Mahmoud
  • 249
  • 1
  • 2
  • 4
20
votes
2 answers

Python Walrus Operator in While Loops

I'm trying to understand the walrus assignment operator. Classic while loop breaks when condition is reassigned to False within the loop. x = True while x: print('hello') x = False Why doesn't this work using the walrus operator? It ignores…
19
votes
5 answers

AttributeError: module 'keras.optimizers' has no attribute 'Adam'

When i am using "optimizer = keras.optimizers.Adam(learning_rate)" i am getting this error "AttributeError: module 'keras.optimizers' has no attribute 'Adam". I am using python3.8 keras 2.6 and backend tensorflow 1.13.2 for running the program.…
Raghu
  • 191
  • 1
  • 1
  • 3
1
2 3
99 100