7

I tried:

print os.name

And the output I got was:

:nt

However, I want output more like "Windows 98", or "Linux".

After suggestions in this question, I also tried:

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

And my output 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?

SilentGhost
  • 307,395
  • 66
  • 306
  • 293

4 Answers4

36

Try:

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

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

Windows XP

After your latest edits, I see that you called your script platform.py. This is causing a naming problem, as when you call platform.system() and platform.release(), it's looking in your file, and not Python's platform module. If you change the name of your file, all of your problems should be resolved.

Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
13

it is because you named your program "platform". Hence when importing the module "platform", your program is imported instead in a circular import.

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

Nicolas Dumazet
  • 7,147
  • 27
  • 36
4
import platform

platform.dist()
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Raghvendra
  • 41
  • 1
  • 1
1

well it depends on the OS: for example I had 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 nor care :P

carlord
  • 11
  • 1