how to write an if-statement in python that incorporates platform.platform
Question:
i am trying to write a program that prints different things depending on the OS and i’m wanting to write an if-statement to do that.I’m new to python but after looking online for a bit i haven’t been able to find any solution
import platform
print('platform:', platform.platform())
if platform.platform == mac0S:
print('this is a mac')
Answers:
I’ll be completing the previous answers and giving some examples.
So first of all you’re going to want to check the platform
Documentation
There you’ll find that platform.platform
is a function that returns a single string, but it includes the MacOS version, which doesn’t suit your example, so we’ll be using platform.system
instead: It returns Windows
, Linux
or Darwin
(for OSX).
import platform
print(platform.system())
if platform.system() == "Darwin":
print("This is a Mac")
elif platform.system() == "Windows":
print("This is a Windows")
elif platform.system() == "Linux":
print("This is a lean, mean, Linux machine")
Hope this helps!
i am trying to write a program that prints different things depending on the OS and i’m wanting to write an if-statement to do that.I’m new to python but after looking online for a bit i haven’t been able to find any solution
import platform
print('platform:', platform.platform())
if platform.platform == mac0S:
print('this is a mac')
I’ll be completing the previous answers and giving some examples.
So first of all you’re going to want to check the platform
Documentation
There you’ll find that platform.platform
is a function that returns a single string, but it includes the MacOS version, which doesn’t suit your example, so we’ll be using platform.system
instead: It returns Windows
, Linux
or Darwin
(for OSX).
import platform
print(platform.system())
if platform.system() == "Darwin":
print("This is a Mac")
elif platform.system() == "Windows":
print("This is a Windows")
elif platform.system() == "Linux":
print("This is a lean, mean, Linux machine")
Hope this helps!