I'm trying to determine if the operating system is Unix-based from a Python script. I can think of two ways to do this but both of them have disadvantages:
platform.system()
is in a tuple such as ("Linux", "Darwin")
. The problem with this is that I don't want to provide a list of every Unix-like system every made, in particular there are many *BSD varieties.os.fchmod
exists, as this function is only available on Unix. This doesn't seem like a clean or "Pythonic" way to do it.import sys
if 'win' in sys.platform():
#windows
else:
#not windows
or, you can try importing a platform dependent library
try:
import windows_only as generic
except ImportException:
try:
import unix_only as generic
except ImportException:
import stdlib.module as generic
print generic.common_function()
and then there's the always reliable
>>> import os
>>> os.name
nt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With