-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.

4
  • 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. Commented Oct 26, 2021 at 13:43
  • 1
    @esqew I think you meant != "Linux"? Commented Oct 26, 2021 at 13:46
  • The != operator should be used when comparing literals / strings, rather than is. This should raise a SyntaxWarning. Commented Oct 26, 2021 at 13:48
  • @OneCricketeer Right, thanks - moving too quickly this morning after my third cup of coffee. if osys != "Linux": Commented Oct 26, 2021 at 13:48

1 Answer 1

0

Try this instead you dont need quotes within the quotes.

if osys != "Linux":

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.