python-3.6

How do I convert a string into an f-string?

▼魔方 西西 提交于 2019-11-27 20:54:03
问题 I was reading this blog on python's new f-strings and they seem really neat. However, I want to be able to load an f-string from a string or file. I can't seem to find any string method or other function that does this. From the example in my link above: name = 'Fred' age = 42 f"My name is {name} and I am {age} years old" 'My name is Fred and I am 42 years old' But what if I had a string s ? I want to be able to eff-ify s , something like this: name = 'Fred' age = 42 s = "My name is {name}

ModuleNotFoundError in tracebacks with Python3.6 on linux

落花浮王杯 提交于 2019-11-27 17:49:12
问题 I installed Python 3.6 on Ubuntu 16.04 by using Jonathon Fernyhough's PPA: sudo add-apt-repository ppa:jonathonf/python-3.6 sudo apt-get update sudo apt-get install python3.6 I made a string, using the new literal string interpolation, but I supplied an invalid format specifier. I not only got the expected ValueError: Invalid format specifier , but also the unexpected ModuleNotFoundError: No module named 'apt_pkg' . $ python3.6 Python 3.6.0 (default, Dec 29 2016, 21:40:36) [GCC 5.4.1 20161202

How to escape f-strings in python 3.6? [duplicate]

拥有回忆 提交于 2019-11-27 17:06:47
问题 This question already has an answer here: How can I print literal curly-brace characters in python string and also use .format on it? 12 answers I have a string in which I would like curly-brackets, but also take advantage of the f-strings feature. Is there some syntax that works for this? Here are two ways it does not work. I would like to include the literal text " {bar} " as part of the string. foo = "test" fstring = f"{foo} {bar}" NameError: name 'bar' is not defined fstring = f"{foo} \

conda install python=3.6 UnsatisfiableError

ε祈祈猫儿з 提交于 2019-11-27 15:27:19
I currently have Python 3.5.2 installed via Anaconda Continuum. I'm trying to upgrade to Python 3.6 but I'm getting the below error when I try to run conda install python=3.6 : UnsatisfiableError: The following specifications were found to be in conflict: - enum34 -> python 2.6*|2.7*|3.3*|3.5* - python ==3.6.0 Use "conda info " to see the dependencies for each package. What might be causing this? You have enum34 installed, which requires 2.6-3.5. Installing Python 3.6 is thus not possible without either updating enum34 to see if newer versions support 3.6, removing enum34, or installing Python

Nested f-strings

ⅰ亾dé卋堺 提交于 2019-11-27 14:16:13
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 >>> f'''-{f"""*{f"+{f'.{x}.'}+"}*"""}-''' '-*+.42.+*-' While I am surprised that this is possible, I am missing on how practical is that, when would nesting f-strings be useful? What use cases can this cover? Note: The PEP itself does not mention nesting f-strings, but there is a specific test case . I don't think formatted string literals allowing nesting (by nesting, I take it to mean f'{f".."}

Error building executable with cx_Freeze: IndexError: tuple index out of range

拜拜、爱过 提交于 2019-11-27 08:42:31
问题 Background I have made a program that I am trying to turn into an executable using CX_Freeze. The setup.py file is placed inside the same directory as all files I am working with. I don't use any extra libraries other than TKinter and OS. The program works perfectly fine normally when I run it via PyCharm>Run Version Numbers cx_Freeze ver: - 5.0 cx_Freeze .whl: - cx_Freeze-5.0-cp36-cp36m-win_amd64.whl python ver: - 3.6.0b4 pycharm ver: - 2016.3.1 This is my setup.py file import cx_Freeze

Python multiprocessing: abort map on first child error

独自空忆成欢 提交于 2019-11-27 08:30:40
问题 What's the proper way of aborting multiprocessing when one of the child aborts and/or throw an Exception? I found various questions around that (generic multiprocessing error handling, how to close multiprocessing pool on exception but without answer, ...), but no clear answer on how to stop multiprocessing on child exception. For instance, I expect the following code: def f(x): sleep(x) print(f"f({x})") return 1.0 / (x - 2) def main(): with Pool(4) as p: try: r = p.map(f, range(7)) except

Create an abstract Enum class

删除回忆录丶 提交于 2019-11-27 06:42:50
问题 I'm trying to create an abstract enum ( Flag actually) with an abstract method. My final goal is to be able to create a string representation of compound enums, based on the basic enums I defined. I'm able to get this functionality without making the class abstract. This is the basic Flag class and an example implementation: from enum import auto, Flag class TranslateableFlag(Flag): @classmethod def base(cls): pass def translate(self): base = self.base() if self in base: return base[self]

pip3 installs inside virtual environment with python3.6 failing due to ssl module not available

*爱你&永不变心* 提交于 2019-11-27 03:16:02
(py36venv) vagrant@pvagrant-dev-vm:/vagrant/venvs$ pip3 install pep8 pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. Collecting pep8 Could not fetch URL https://pypi.python.org/simple/pep8/ : There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping Could not find a version that satisfies the requirement pep8 (from versions: ) No matching distribution found for pep8 Background information - Trying to move to python 3.6. Installed python3.6 using the below commands:

Python 3.6 No module named pip

↘锁芯ラ 提交于 2019-11-27 02:32:31
问题 I have just installed Python 3.6 on Fedora 25 (64 bits) by running dnf install python36 and I can't use any modules Python 3.5 can otherwise use just fine, for example, PyCharm complains about setup tools not being installed, also I can run python3 and issue: import aiohttp However, if run python36 and then: import aiohttp I instead get: Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'aiohttp' Pip is also not present on python36, as python36 -m pip