So I have written this module:
plaform.py
from enum import IntFlag
class PlatformFlag(IntFlag):
LINUX = 1,
MACOSX = 2,
WINDOWS = 3
globals().update(PlatformFlag.__members__)
And I am trying to use it this way:
import platform
if __name__ == '__main__':
if platform.WINDOWS:
print("This is Windows!")
However, I get:
"Exception has occurred: AttributeError module 'platform' has no attribute 'WINDOWS'"
This works:
import platform
if __name__ == '__main__':
if platform.PlatformFlag.WINDOWS:
print("This is Windows!")
However, this is NOT the desired way of doing it. I am thinking about the re.py in cPython. They way you can invoke this e.g. re.compile(pattern, flags=re.M). However, for some reason unknown to me, the globals().upate() doesn't seem to do the trick, or I am missing something here.
Re.py:
https://github.com/python/cpython/blob/master/Lib/re.py
EDIT: This deserves credit, https://repl.it/@JoranBeasley/IntentionalPastStrategies