Skip to content

Tag: python-3.x

Linking python enums

I have some Enum classes that I want to link up recursively. Looking at the line color = ItemColors[Items(value)._name_].value.value, it seems a bit clunky. Am I misunderstanding something about Enum usage? Is there a better way to do it? Answer Building on @brni’s answer, I came up with a smoother solu…

Why doesn’t contextmanager reraise exception?

I want to replace class’s __enter__/__exit__ functions with single function decorated as contextlib.contextmanager, here’s code: When we got exception inside Test’s __exit__, we pass it to _cm’s __exit__, it works fine, I see exception inside _cm. But then, when I decide to reraise ins…

no module named fuzzywuzzy

I installed fuzzywuzzy with pip for python3. When I do pip list I see However when I try to import is I get an error. Does anyone have experience with this problem? Answer Are you sure you ran pip3 and not just pip? The latter only installs Python 2 packages.

Iterating over two lists one after another

I have two lists list1 and list2 of numbers, and I want to iterate over them with the same instructions. Like this: But that feels redundant. I know I can write for item in list1 + list2:, but it has a price of running-time. Is there a way do that without loose time? Answer This can be done with itertools.cha…