I came across this interesting question my friend asked me. He told that he found a way to know which os we are on without importing the os module. Can any of you help me with the same?
Asked
Active
Viewed 37 times
-3
ForceBru
- 41,233
- 10
- 61
- 89
-
For example: `import platform; platform.uname()` – ForceBru Mar 13 '21 at 11:21
-
1Does this answer your question? [Python: What OS am I running on?](https://stackoverflow.com/questions/1854/python-what-os-am-i-running-on) – Gino Mempin Mar 13 '21 at 11:27
2 Answers
1
import platform
print(platform.system())
print(platform.release())
print(platform.version())
liagason
- 101
- 1
- 10
-
`platform` imports `os`, so maybe this is not what the OP wanted. – Christian K. Mar 13 '21 at 11:29
0
perhaps this could work:
if r"\" in __file__: print("Windows")
else: print("Unix variant")
Alain T.
- 34,859
- 4
- 30
- 47