How to get operating system name in a friendly manner using Python 2.5?

I tried:

print os.name 

And I got the result:

 :nt 

However, I want the result to be more like "Windows 98" or "Linux."

After suggestions on this, I also tried:

 import os print os.name import platform print platform.system() print platform.release() 

And my result was:

 Traceback (most recent call last): File "C:/Documents and Settings/BIU1LR/Desktop/python_programs/program/platform.py", line 3, in <module> import platform File "C:/Documents and Settings/BIU1LR/Desktop/python_programs/program\platform.py", line 4, in <module> print platform.system() AttributeError: 'module' object has no attribute 'system' 

I am using Python 2.5.2. What am I doing wrong?

+7
python
source share
4 answers

Try:

 import platform print platform.system(), platform.release() 

I tried this on my computer with Python 2.6, and I got this as output:

 Windows XP 

After your last changes, I see that you have called your script platform.py. This causes a naming problem, for example, when you call platform.system() and platform.release() , it looks in your file, not the Python platform module. If you change the name of your file, all your problems should be resolved.

+36
source share

this is because you called your program "platform." Therefore, when you import the platform module, your program is imported instead into a round-robin import.

Try renaming the file to test_platform.py and it will work.

+13
source share
 import platform platform.dist() 
+4
source share

Well, it depends on the OS: for example, I tested

  platform.system() - in linux works, AIX works platform.release()- in linux works, AIX gives a weird '1' with non other info platform.dist() - in linux works, AIX gives a nothing '','','' os.name - resolves 'posix' in both :S 

Windows I really don't test or care: P

+1
source share

All Articles