-6

I am trying to check is osys variable is not equal to 'Linux'. The output of platform.system() on my machine is 'Linux'. This then gets assigned to the variable of osys.

def getos():
osys=platform.system()
if osys is not "'Linux'":
    print(color.lightred + "This program only runs on Linux operating systems.")
    time.sleep(2)
    quit()
getos()

I am using this code to check if osys is 'Linux', and if not the program will close because the program only works on linux. Instead when I run this code I always get the output string of This program only runs on Linux operating systems instead of the code just continuing. Does anyone know how to fix this.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • 2
    What about `if osys is not "Linux":`...? It's not clear why you've opted to include single quotes *inside* your string here. Voting to close as a typographical error. – esqew Oct 26 '21 at 13:43
  • 1
    @esqew I think you meant `!= "Linux"`? – OneCricketeer Oct 26 '21 at 13:46
  • The `!=` operator should be used when comparing literals / strings, rather than `is`. This should raise a `SyntaxWarning`. – S3DEV Oct 26 '21 at 13:48
  • @OneCricketeer Right, thanks - moving too quickly this morning after my third cup of coffee. `if osys != "Linux":` – esqew Oct 26 '21 at 13:48

1 Answers1

0

Try this instead you dont need quotes within the quotes.

if osys != "Linux":

anarchy
  • 3,709
  • 2
  • 16
  • 48