Get OS name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • codecraig

    #1

    Get OS name

    How can I get the OS Name, such as "Windows XP Pro". I know I can do

    sys.getwindowsv ersion but that doesnt return a nice Windows XP Pro
    string.

    and os.name gives "nt"

    thanks.

  • rbt

    #2
    Re: Get OS name

    codecraig wrote:[color=blue]
    > How can I get the OS Name, such as "Windows XP Pro". I know I can do
    >
    > sys.getwindowsv ersion but that doesnt return a nice Windows XP Pro
    > string.
    >
    > and os.name gives "nt"
    >
    > thanks.
    >[/color]

    Read the docs... sys.getwindowsv ersion() should do the trick. AFAIK,
    there is no way to differentiate between XP Home and Pro unless you
    attempt to call an executable that's only available on Pro... such as
    "systeminfo ". If that call fails, it's reasonably safe to assume that
    you're on a XP Home machine... especially if getwindowsversi on()
    produces a major of 5 and a minor of 1

    As everyone knows that XP is really just NT 5.1 ;)

    Comment

    • codecraig

      #3
      Re: Get OS name

      i guess i wanted the result in a nice string like Windows XP instead of
      5.1

      i guess i'll have to convert it myself, thanks

      Comment

      • Fredrik Lundh

        #4
        Re: Get OS name

        "codecraig" wrote:
        [color=blue]
        > How can I get the OS Name, such as "Windows XP Pro"[/color]
        [color=blue]
        >i guess i wanted the result in a nice string like Windows XP instead of
        > 5.1
        >
        > i guess i'll have to convert it myself, thanks[/color]

        your requirements keep changing. to get the OS name in a platform-
        independent way, use the platform module:
        [color=blue]
        > python[color=green][color=darkred]
        >>> import platform
        >>> print platform.system (), platform.releas e()[/color][/color][/color]
        Windows XP

        $ python[color=blue][color=green][color=darkred]
        >>> import platform
        >>> print platform.system (), platform.releas e()[/color][/color][/color]
        Linux 2.4.18-3

        etc.

        (tip: reading the "library reference" table of contents a couple of times is a great way
        to learn about the contents of the standard library. http://docs.python.org/lib/lib.html )

        </F>



        Comment

        • codecraig

          #5
          Re: Get OS name

          my requirements for getting the OS info havent changed. My first
          message says "How can I get the OS Name, such as "Windows XP Pro"."
          .....that's what I wanted all along.

          thanks for the information anyway, i believe platform is better than my
          previous approach.

          thanks

          Comment

          • A.B., Khalid

            #6
            Re: Get OS name

            codecraig wrote:[color=blue]
            > my requirements for getting the OS info havent changed. My first
            > message says "How can I get the OS Name, such as "Windows XP Pro"."
            > ....that's what I wanted all along.
            >
            > thanks for the information anyway, i believe platform is better than[/color]
            my[color=blue]
            > previous approach.
            >
            > thanks[/color]



            Please note that platform appears to require win32api to be in your
            system. The following is the code from \Lib\platform.p y.

            The function that gets the data sets these values as default

            [Code from platform.py]
            def win32_ver(relea se='',version=' ',csd='',ptype= ''):
            [/Code]

            And will return empty strings in case win32api is not found:

            [Code from platform.py]
            # Import the needed APIs
            try:
            import win32api
            except ImportError:
            return release,version ,csd,ptype
            [/Code from platform.py]


            Accordingly, my Python 2.3.5 final which has win32api installed can get
            the platform answer right:

            $ /py23/python/dist/src/MinGW/python -i
            Python 2.3.5 (#62, Feb 12 2005, 02:56:20)
            [GCC 3.4.2 (mingw-special)] on win32
            Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
            >>> import platform
            >>> print platform.system (), platform.releas e()[/color][/color][/color]
            Windows 98[color=blue][color=green][color=darkred]
            >>>[/color][/color][/color]



            But where I don't have win32api installed, my Python does not know that
            answer you seek:


            $ /py25/python/dist/src/MinGW/python -i
            Python 2.5a0 (#65, Apr 12 2005, 20:22:54)
            [GCC 3.4.2 (mingw-special)] on win32
            Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
            >>> import platform
            >>> print platform.system (), platform.releas e()[/color][/color][/color]
            Windows[color=blue][color=green][color=darkred]
            >>>[/color][/color][/color]



            Regards,
            Khalid

            Comment

            Working...