Questions tagged [python-3.6]

Version of the Python programming language released in December 2016. For issues specific to Python 3.6. Use more generic [python] and [python-3.x] tags where possible.

Python 3.6 is the currently newest version of the popular Python programming language (see PEP 0494).

Use this tag if your question is specifically related to Python 3.6. 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

5657 questions
736
votes
6 answers

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” representation pioneered by PyPy. The memory usage of the…
Chris_Rands
  • 38,994
  • 14
  • 83
  • 119
265
votes
5 answers

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 – the solid thin line near the dot at self.text is the 80 char mark. I'm trying to split it into different lines…
Owlzy
  • 3,352
  • 2
  • 12
  • 12
258
votes
6 answers

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

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 p_03_using_bisection_search.py The code inside…
lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
239
votes
8 answers

How can I use newline '\n' in an f-string to format output?

I tried this code: names = ['Adam', 'Bob', 'Cyril'] text = f"Winners are:\n{'\n'.join(names)}" print(text) However, '\' cannot be used inside the {...} expression portions of an f-string. How can I make it work? The result should be: Winners…
malmed
  • 2,698
  • 2
  • 13
  • 11
186
votes
22 answers

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
  • 12,146
  • 18
  • 64
  • 109
186
votes
8 answers

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 have found so far are as follows downloading an old…
user7396807
  • 1,889
  • 3
  • 9
  • 5
179
votes
15 answers

How to postpone/defer the evaluation of f-strings?

I am using template strings to generate some files and I love the conciseness of the new f-strings for this purpose, for reducing my previous template code from something like this: template_a = "The current name is {name}" names = ["foo",…
JDAnders
  • 4,831
  • 4
  • 10
  • 8
137
votes
1 answer

Rounding floats with f-string

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 Python 3.6?
elsoja
  • 1,567
  • 2
  • 9
  • 7
129
votes
6 answers

ModuleNotFoundError: No module named 'distutils.core'

I've recently upgraded from Ubuntu 18.04 to 19.04 which has python 3.7. But I work on many projects using Python 3.6. Now when I try to create a virtualenv with Python 36 in PyCharm, it raises: ModuleNotFoundError: No module named…
Milano
  • 18,048
  • 37
  • 153
  • 353
125
votes
1 answer

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

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
  • 1,531
  • 2
  • 11
  • 19
120
votes
5 answers

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 called whenever the containing class is…
EsotericVoid
  • 2,306
  • 2
  • 16
  • 25
118
votes
14 answers

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 it was the missing package. So my question is, how…
Studentu
  • 1,375
  • 2
  • 10
  • 11
117
votes
1 answer

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, audacious.mode) PNG (1094, 960) RGBA When I tried to…
user9062604
95
votes
4 answers

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 import aiohttp urls = ['http://www.google.com',…
Jirka Svítil
  • 1,134
  • 1
  • 7
  • 10
90
votes
15 answers

Nested f-strings

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}" '*************$478.23' Or: >>> x = 42 >>>…
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
1
2 3
99 100