Last active
December 3, 2021 10:36
-
-
Save tai271828/6009797f4ffdcfe4430bcc7661a60a4c to your computer and use it in GitHub Desktop.
Python solution candidates of namespace for flags or attributes
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
#!/usr/bin/env python3 | |
from enum import Enum | |
from collections import namedtuple | |
# use dict | |
status_dict = { | |
"REPORTED": "已檢舉", | |
"AUDIT_SCHEDULED": "已排程稽查" | |
} | |
# use collections - namedtuple | |
investigation_namedtuple = namedtuple("InvestigationNT", ["REPORTED", "AUDIT_SCHEDULED"]) | |
status_namedtuple = investigation_namedtuple("已檢舉", AUDIT_SCHEDULED="已排程稽查") | |
# use typing.NamedTuple | |
# use types.SimpleNamespace() | |
# use enum ... maybe not a good idea hear because our values are string |
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
#!/usr/bin/env python3 | |
from flags import * | |
print(status_dict["REPORTED"]) | |
print(type(status_dict["REPORTED"])) | |
print(status_namedtuple.REPORTED) | |
print(type(status_namedtuple.REPORTED)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment