how to determine Operating System in Use?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ian F. Hood

    #1

    how to determine Operating System in Use?

    Hi
    In typically windows environments I have used:
    if 'Windows' in os.environ['OS']...
    to prove it, but now I need to properly support different environments.
    To do so I must accurately determine what system the python instance is
    running on (linux, win, mac, etc).
    Is there a best practises way to do this?
    TIA
    Ian



  • nanjundi@gmail.com

    #2
    Re: how to determine Operating System in Use?



    On Dec 13, 6:32 pm, "Ian F. Hood" <IanFH...@gmail .comwrote:
    Hi
    In typically windows environments I have used:
    if 'Windows' in os.environ['OS']...
    to prove it, but now I need to properly support different environments.
    To do so I must accurately determine what system the python instance is
    running on (linux, win, mac, etc).
    Is there a best practises way to do this?
    TIA
    Ian
    I would do this:
    --------------------
    if os.name == ''posix':
    linuxStuff()
    elif os.name == 'nt':
    windowsStuff()
    elif os.name == 'os2': ...
    -------------------
    os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'

    -N

    Comment

    • Paul Watson

      #3
      Re: how to determine Operating System in Use?

      Ian F. Hood wrote:
      Hi
      In typically windows environments I have used:
      if 'Windows' in os.environ['OS']...
      to prove it, but now I need to properly support different environments.
      To do so I must accurately determine what system the python instance is
      running on (linux, win, mac, etc).
      Is there a best practises way to do this?
      TIA
      Ian
      The more significant question is "why" do you want to do this? Are you
      writing an asset management tool? Do you just want to tell the user
      what operating system they are using? The reason may lead to a
      different solution.

      Comment

      • Ian F. Hood

        #4
        Re: how to determine Operating System in Use?

        I am integrating with an existing cross-platform system that provides
        different shell scripts and/or batch files for each environment. Normally
        the selection is performed manually but my utility needs to automate this.
        To select the correct utility I need to know what platform my code is
        running on.

        "Paul Watson" <pwatson@redlin epy.comwrote in message
        news:4ubttfF17m 7vaU1@mid.indiv idual.net...
        Ian F. Hood wrote:
        >Hi
        >In typically windows environments I have used:
        > if 'Windows' in os.environ['OS']...
        >to prove it, but now I need to properly support different environments.
        >To do so I must accurately determine what system the python instance is
        >running on (linux, win, mac, etc).
        >Is there a best practises way to do this?
        >TIA
        >Ian
        >
        The more significant question is "why" do you want to do this? Are you
        writing an asset management tool? Do you just want to tell the user
        what operating system they are using? The reason may lead to a
        different solution.
        --

        >


        Comment

        • Ian F. Hood

          #5
          Re: how to determine Operating System in Use?

          excellent, ty

          <nanjundi@gmail .comwrote in message
          news:1166056094 .751283.122760@ 79g2000cws.goog legroups.com...
          >
          >
          On Dec 13, 6:32 pm, "Ian F. Hood" <IanFH...@gmail .comwrote:
          >Hi
          >In typically windows environments I have used:
          > if 'Windows' in os.environ['OS']...
          >to prove it, but now I need to properly support different environments.
          >To do so I must accurately determine what system the python instance is
          >running on (linux, win, mac, etc).
          >Is there a best practises way to do this?
          >TIA
          >Ian
          >
          I would do this:
          --------------------
          if os.name == ''posix':
          linuxStuff()
          elif os.name == 'nt':
          windowsStuff()
          elif os.name == 'os2': ...
          -------------------
          os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
          >
          -N
          >
          --

          >


          Comment

          • James Cunningham

            #6
            Re: how to determine Operating System in Use?

            On 2006-12-13 19:28:14 -0500, nanjundi@gmail. com said:
            >
            >
            On Dec 13, 6:32 pm, "Ian F. Hood" <IanFH...@gmail .comwrote:
            >Hi
            >In typically windows environments I have used:
            >if 'Windows' in os.environ['OS']...
            >to prove it, but now I need to properly support different environments.
            >To do so I must accurately determine what system the python instance is
            >running on (linux, win, mac, etc).
            >Is there a best practises way to do this?
            >TIA
            >Ian
            >
            I would do this:
            --------------------
            if os.name == ''posix':
            linuxStuff()
            elif os.name == 'nt':
            windowsStuff()
            elif os.name == 'os2': ...
            -------------------
            os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
            >
            -N
            Bearing in mind, of course, that Mac will return "posix", too. And
            Cygwin might. Erg.

            Best,
            James

            Comment

            • Prateek

              #7
              Re: how to determine Operating System in Use?

              also try:

              sys.platform

              if sys.platform == "darwin":
              macStuff()
              elif sys.platform == "win32":
              linuxStuff()


              James Cunningham wrote:
              On 2006-12-13 19:28:14 -0500, nanjundi@gmail. com said:
              >


              On Dec 13, 6:32 pm, "Ian F. Hood" <IanFH...@gmail .comwrote:
              Hi
              In typically windows environments I have used:
              if 'Windows' in os.environ['OS']...
              to prove it, but now I need to properly support different environments.
              To do so I must accurately determine what system the python instance is
              running on (linux, win, mac, etc).
              Is there a best practises way to do this?
              TIA
              Ian
              I would do this:
              --------------------
              if os.name == ''posix':
              linuxStuff()
              elif os.name == 'nt':
              windowsStuff()
              elif os.name == 'os2': ...
              -------------------
              os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'

              -N
              >
              Bearing in mind, of course, that Mac will return "posix", too. And
              Cygwin might. Erg.
              >
              Best,
              James

              Comment

              • Prateek

                #8
                Re: how to determine Operating System in Use?

                eeps! typo.
                if sys.platform == "darwin":
                macStuff()
                elif sys.platform == "win32":
                winStuff()
                >
                Not sure what the string is on linux. Just fire up the interpreter and
                try it.

                Prateek

                Prateek wrote:
                also try:
                >
                sys.platform
                >
                if sys.platform == "darwin":
                macStuff()
                elif sys.platform == "win32":
                linuxStuff()
                >
                >
                James Cunningham wrote:
                On 2006-12-13 19:28:14 -0500, nanjundi@gmail. com said:
                >
                >
                On Dec 13, 6:32 pm, "Ian F. Hood" <IanFH...@gmail .comwrote:
                >Hi
                >In typically windows environments I have used:
                >if 'Windows' in os.environ['OS']...
                >to prove it, but now I need to properly support different environments.
                >To do so I must accurately determine what system the python instance is
                >running on (linux, win, mac, etc).
                >Is there a best practises way to do this?
                >TIA
                >Ian
                >
                I would do this:
                --------------------
                if os.name == ''posix':
                linuxStuff()
                elif os.name == 'nt':
                windowsStuff()
                elif os.name == 'os2': ...
                -------------------
                os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
                >
                -N
                Bearing in mind, of course, that Mac will return "posix", too. And
                Cygwin might. Erg.

                Best,
                James

                Comment

                Working...