How do I get the operating system name in a friendly manner using Python 2.5?

2024/10/14 4:29:03

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 platformFile "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?

Answer

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.

https://en.xdnf.cn/q/69453.html

Related Q&A

Extend dataclass __repr__ programmatically

Suppose I have a dataclass with a set method. How do I extend the repr method so that it also updates whenever the set method is called: from dataclasses import dataclass @dataclass class State:A: int …

find least common denominator for list of fractions in python

I have a list of fractionsfrom fractions import Fractionfractions_list=[Fraction(3,14),Fraction(1,7),Fraction(9,14)]The output should be a list with the numerators for each fraction, then the denominat…

How to configure uwsgi to encode logging as json except app output

Im running uwsgi around a Python Flask webapp with these options (among others) to get JSON-encoded log records on stdout:fmt=${"timestamp": "${strftime:%FT%TZ}", "level":…

Testing aiohttp client with unittest.mock.patch

Ive written a simple HTTP client using aiohttp and Im trying to test it by patching aiohttp.ClientSession and aiohttp.ClientResponse. However, it appears as though the unittest.mock.patch decorator is …

GridsearchCV: cant pickle function error when trying to pass lambda in parameter

I have looked quite extensively on stackoverflow and elsewhere and I cant seem to find an answer to the problem below. I am trying to modify a parameter of a function that is itself a parameter inside …

How to insert a carriage return in a ReportLab paragraph?

Is there a way to insert a carriage return in a Paragraph in ReportLab? I am trying to concatenate a "\n" to my paragraph string but this isnt working. Title = Paragraph("Title" + …

How to get predictions and calculate accuracy for a given test set in fast ai?

Im trying to load a learner which was exported by learn.export() and I want to run it against a test set. I want my test set have labels so that I can measure its accuracy. This is my code: test_src = …

Splitting the legend in matploblib

Is it possible to split up a single big legend into multiple (usually 2) smaller ones.from pylab import *t = arange(0.0, 2.0, 0.01) s = sin(2*pi*t) plot(t, s, linewidth=1.0, label="Graph1") g…

Python 3.x - iloc throws error - single positional indexer is out-of-bounds

I am scraping election data from a website and trying to store it in a dataframe import pandas as pd import bs4 import requestscolumns = [Candidate,Party,Criminal Cases,Education,Age,Total Assets,Liabi…

Supposed automatically threaded scipy and numpy functions arent making use of multiple cores

I am running Mac OS X 10.6.8 and am using the Enthought Python Distribution. I want for numpy functions to take advantage of both my cores. I am having a problem similar to that of this post: multithre…