what is the best way to determine system OS?

Fredrik Lundh fredrik at pythonware.com
Mon Apr 25 10:32:14 EDT 2005


"googleboy" <mynews44 at yahoo.com> wrote:

> I am writing a little app tha tI would like to make cross-platform
> (debian, RH, Fedora, Solaris, AIX, etc)
>
> Originally I decided to check what uname returned, as I didn't think it
> mattered beyond the detail of Linux or SunOS etc.
>
> Recently I have learned that FC3 breaks my script,  so I need to be
> able to determine not simply "Linux" but to know exactly what unix the
> script is being run on.
>
> What is the best way to determine this?

start here:

    >>> help("platform")

if that doesn't help, something like this could work:

    >>> redhat = open("/etc/redhat-release").read()
    >>> fedora_3 = redhat.startswith("Fedora Core release 3")

(with proper use of try/except, of course)

on the other hand, it might be better to figure out why FC3 breaks your
script, and check for (missing/alternative) features instead of checking for
the exact OS version.

</F> 






More information about the Python-list mailing list