nonlocal in Python 3
#TIL about nonlocal in Python 3 Inner functions can access outer variables but can’t modify them by default Here’s a contrived simple example def outer(): num = 0 def inner(): nonlocal num num += 1 inner() If you remove t...
Search for a command to run...
Articles tagged with #python
#TIL about nonlocal in Python 3 Inner functions can access outer variables but can’t modify them by default Here’s a contrived simple example def outer(): num = 0 def inner(): nonlocal num num += 1 inner() If you remove t...
Final from typing import Final _PI: Final[float] = 3.14 Hashable from typing import Any, Dict from collections.abc import Hashable my_dict: Dict[Hashable, Any] TypedDict # Python >= 3.11 from typing import Optional, NotRequired, TypedDict # Pyth...
which is the opposite order for Jestexpect(myVar).toBe(42) assumes the first is expected, second is actual in the error message. self.assertEqual(expected, actual) self.assertEqual(42, my_var) PyCharm even displays Expected and Actual Failure Expect...
PIP_REQUIRE_VIRTUALENV=truein your .zshrc (or env variables) prevents you from pip installing globally so that you only run pip install in a venv Only use pipx for global installs
Why do something like this? subprocess.check_call( ( "git", *("-c", "protocol.version=2") *("--depth", "1"), ) ) Because the black formatter will format it like this which is less readable subprocess.check_call( (...