Create an abstract Enum class

Here’s how to adapt the accepted answer to the question Abstract Enum Class using ABCMeta and EnumMeta to create the kind of abstract Enum class you want: from abc import abstractmethod, ABC, ABCMeta from enum import auto, Flag, EnumMeta class ABCEnumMeta(ABCMeta, EnumMeta): def __new__(mcls, *args, **kw): abstract_enum_cls = super().__new__(mcls, *args, **kw) # Only check abstractions … Read more

Python and F-Strings explanation

No, ‘snow’ is a string literal, an expression that produces a string value. snow would be a variable name (note the lack of quotes). Compare: >>> ‘snow’ ‘snow’ >>> snow Traceback (most recent call last): File “<stdin>”, line 1, in <module> NameError: name ‘snow’ is not defined >>> snow = 42 >>> snow 42 >>> … Read more

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

You can’t. Backslashes cannot appear inside the curly braces {}; doing so results in a SyntaxError: >>> f'{\}’ SyntaxError: f-string expression part cannot include a backslash This is specified in the PEP for f-strings: Backslashes may not appear inside the expression portions of f-strings, […] One option is assinging ‘\n’ to a name and then … Read more

Nested f-strings

I don’t think formatted string literals allowing nesting (by nesting, I take it to mean f'{f”..”}’) is a result of careful consideration of possible use cases, I’m more convinced it’s just allowed in order for them to conform with their specification. The specification states that they support full Python expressions* inside brackets. It’s also stated … Read more

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

I followed the below steps for python3.6 installation in ubuntu 14.04 and virtualenv pip installs works fine. Python 3.6 Installation: sudo apt-get install python3-dev libffi-dev libssl-dev wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz tar xvf Python-3.6.0.tgz cd Python-3.6.0 ./configure –enable-optimizations make -j8 sudo make altinstall python3.6 If seeing the following error — zipimport.ZipImportError: can’t decompress data; zlib not available make: … Read more