How to identify on which OS Python is running on?
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Track title: CC M Beethoven - Piano Sonata No 3 in C 3
--
Chapters
00:00 Question
00:19 Accepted answer (Score 1176)
00:51 Answer 2 (Score 214)
01:23 Answer 3 (Score 146)
01:37 Answer 4 (Score 115)
01:56 Thank you
--
Full question
https://stackoverflow.com/questions/1854...
Accepted answer links:
[platform.system()]: https://docs.python.org/library/platform...
[platform]: https://docs.python.org/library/platform...
Answer 2 links:
[Dang -- Louis Brandy beat me to the punch]: https://stackoverflow.com/a/1857/4298200
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #operatingsystem #crossplatform #platformagnostic
#avk47
--
Track title: CC M Beethoven - Piano Sonata No 3 in C 3
--
Chapters
00:00 Question
00:19 Accepted answer (Score 1176)
00:51 Answer 2 (Score 214)
01:23 Answer 3 (Score 146)
01:37 Answer 4 (Score 115)
01:56 Thank you
--
Full question
https://stackoverflow.com/questions/1854...
Accepted answer links:
[platform.system()]: https://docs.python.org/library/platform...
[platform]: https://docs.python.org/library/platform...
Answer 2 links:
[Dang -- Louis Brandy beat me to the punch]: https://stackoverflow.com/a/1857/4298200
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #operatingsystem #crossplatform #platformagnostic
#avk47
ACCEPTED ANSWER
Score 1298
>>> import os
>>> os.name
'posix'
>>> import platform
>>> platform.system()
'Linux'
>>> platform.release()
'2.6.22-15-generic'
The output of platform.system() is as follows:
- Linux:
Linux - Mac:
Darwin - Windows:
Windows
See: platform — Access to underlying platform’s identifying data
ANSWER 2
Score 222
Here are the system results for Windows Vista!
>>> import os
>>> os.name
'nt'
>>> import platform
>>> platform.system()
'Windows'
>>> platform.release()
'Vista'
And for Windows 10:
>>> import os
>>> os.name
'nt'
>>> import platform
>>> platform.system()
'Windows'
>>> platform.release()
'10'
ANSWER 3
Score 149
For the record, here are the results on Mac:
>>> import os
>>> os.name
'posix'
>>> import platform
>>> platform.system()
'Darwin'
>>> platform.release()
'8.11.1'
ANSWER 4
Score 118
Sample code to differentiate operating systems using Python:
import sys
if sys.platform.startswith("linux"): # could be "linux", "linux2", "linux3", ...
# linux
elif sys.platform == "darwin":
# MAC OS X
elif os.name == "nt":
# Windows, Cygwin, etc. (either 32-bit or 64-bit)