Created
April 15, 2023 10:59
-
-
Save hseritt/8a7e06b8dd2a15149fde99e751976b55 to your computer and use it in GitHub Desktop.
Using namedtuple for constants in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
Socket = namedtuple("Socket", ["DEFAULT_TIMEOUT"]) | |
# Set a default timeout for sockets | |
SOCKET = Socket(DEFAULT_TIMEOUT=10) | |
print(SOCKET.DEFAULT_TIMEOUT) | |
try: | |
SOCKET.DEFAULT_TIMEOUT = 40 | |
except AttributeError: | |
print "This won't work" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment