Pythons platform.system() gives me str object has no attribute system but only in script

Question:

If I do like this in the python prompt:

import platform

platform.system()

I get Linux as expected.

However if I do like this in my script:

import platform
if(platform.system() == "windows"):
 print x
else:
  print y

I just get this error messsage.
AttributeError: str object has no attribute system

I am quite new to Python but this puzzles me a bit so if anyone can point to the problem I would be grateful.

Asked By: user1192315

||

Answers:

Somewhere in your script you have a variable called platform that shadows the module with the same name.

Answered By: NPE

your if statement has unneeded parenthesis. Im assuming you’re used to using a language that needs the condition to be wrapped in them.

Your code:

import platform
if(platform.system() == "windows"):
 print x
else:
  print y

Fixed code:

import platform
if platform.system() == "windows":
 print x
else:
  print y
Answered By: QAEZZ
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.