Skip to main content
769 votes
6 answers
340k views

Are dictionaries ordered in Python 3.6+?

Dictionaries are insertion ordered as of Python 3.6. It is described as a CPython implementation detail rather than a language feature. The documentation states: dict() now uses a “compact” ...
Chris_Rands's user avatar
  • 41.4k
308 votes
5 answers
304k views

Multiline f-string in Python

I'm trying to write PEP-8 compliant code for a domestic project and I have a line with an f-string that is more than 80 characters long: def __str__(self): return f'{self.data} - {self.time},\...
Owlzy's user avatar
  • 4,072
260 votes
6 answers
345k views

ModuleNotFoundError: What does it mean __main__ is not a package? [duplicate]

I am trying to run a module from the console. The structure of my directory is this: I am trying to run the module p_03_using_bisection_search.py, from the problem_set_02 directory using: $ python3 ...
lmiguelvargasf's user avatar
190 votes
22 answers
193k views

Why Python 3.6.1 throws AttributeError: module 'enum' has no attribute 'IntFlag'?

I just installed Python 3.6.1 for MacOS X When I attempt to run the Console(or run anything with Python3), this error is thrown: AttributeError: module 'enum' has no attribute 'IntFlag' $ /...
BryanWheelock's user avatar
190 votes
8 answers
616k views

How can I convert a .py to .exe for Python?

I'm trying to convert a fairly simple Python program to an executable and couldn't find what I was looking for, so I have a few questions (I'm running Python 3.6): The methods of doing this that I ...
user7396807's user avatar
  • 1,929
159 votes
1 answer
64k views

In Python format (f-string) strings, what does !r mean? [duplicate]

I get what the new f strings in python 3.6 do, but what about the ending !r as found in the code snip below. def __repr__(self): return (f'Pizza({self.radius!r}, 'f'{self.ingredients!r})')
nk abram's user avatar
  • 1,871
155 votes
1 answer
183k views

Rounding floats with f-string [duplicate]

Using %-formatting, I can specify the number of decimal cases in a string: x = 3.14159265 print('pi = %0.2f' %x) This would give me: pi = 3.14 Is there any way of doing this using f-strings in ...
elsoja's user avatar
  • 1,757
148 votes
2 answers
161k views

cannot write mode RGBA as JPEG

I am learning to use 'pillow 5.0' following book 'Automate the boring stuff with python' The info about the image object In [79]: audacious = auda In [80]: print(audacious.format, audacious.size, ...
user avatar
144 votes
5 answers
109k views

Understanding __init_subclass__

I finally upgraded my python version and I was discovering the new features added. Among other things, I was scratching my head around the new __init_subclass__ method. From the docs: This method is ...
EsotericVoid's user avatar
  • 2,606
139 votes
16 answers
575k views

Pip error: Microsoft Visual C++ 14.0 is required

I just ran the following command: pip install -U steem and the installation worked well until it failed to install pycrypto. Afterwards I did the pip install cryptography command because I thought ...
Studentu's user avatar
  • 1,595
134 votes
6 answers
158k views

ModuleNotFoundError: No module named 'distutils.core'

This question asks: "I do everything right, but nothing happens!" See this question for getting technical info about how to solve the direct cause of this error message. I've recently ...
Milano's user avatar
  • 18.8k
104 votes
17 answers
78k views

What are use cases for nested f-strings [closed]

Thanks to David Beazley's tweet, I've recently found out that the new Python 3.6 f-strings can also be nested: >>> price = 478.23 >>> f"{f'${price:0.2f}':*>20s}" '*************$...
alecxe's user avatar
  • 475k
98 votes
5 answers
161k views

Python3.6 AttributeError: module 'asyncio' has no attribute 'run'

I tried to read https://hackernoon.com/asynchronous-python-45df84b82434. It's about asynchronous python and I tried the code from this, but I'm getting a weird Error. The code is: ` import asyncio ...
Jirka Svítil's user avatar
97 votes
1 answer
61k views

what does --enable-optimizations do while compiling python?

I'm trying to compile Python 3.6 on an arm based Linux machine, ./configure outputs this: If you want a release build with all optimizations active (LTO, PGO, etc), please run ./configure --...
Yashar's user avatar
  • 2,723
89 votes
5 answers
130k views

How to call a async function from a synchronized code Python

So I'm locked to a python 3.6.2 interpreter that follows my desktop application. What I want is to call an async function from a synchronized method or function. When calling the python function from ...
Paal Pedersen's user avatar

15 30 50 per page
1
2 3 4 5
374