from enum import IntFlag
class PlatformFlag(IntFlag):
LINUX = 1,
MACOSX = 2,
WINDOWS = 3
globals().update(PlatformFlag.__members__)
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'"
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.
https://github.com/python/cpython/blob/master/Lib/re.py
EDIT: This deserves credit, https://repl.it/@JoranBeasley/IntentionalPastStrategies
The problem you have comes from naming, as there is a builtin module called platform.
https://docs.python.org/3.7/library/platform.html
Running your code with another name like platform123.py works. However the functionality to determine which OS is running is not part of your code and as such does not work :)
The way RE works is by taking the flags as input to the functions. The globals().update(xx.__members__) only makes the members of the classes available in the global namespace so you can use platform.WINDOWS instead of platform.PlatformFlag.WINDOWS.