Skip to content

Instantly share code, notes, and snippets.

@tai271828
Last active December 3, 2021 10:36
Show Gist options
  • Save tai271828/6009797f4ffdcfe4430bcc7661a60a4c to your computer and use it in GitHub Desktop.
Save tai271828/6009797f4ffdcfe4430bcc7661a60a4c to your computer and use it in GitHub Desktop.
Python solution candidates of namespace for flags or attributes
#!/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
#!/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