Search code examples
pythonplatform

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


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.


Solution

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