porting python script from linux to windows

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

    porting python script from linux to windows

    What are the specific steps that one should take to make a python script
    that works on a Linux x86 machine also work on a Windows x86 machine?

    I am using os, re and string in the script. How do paths differ between
    the two OSes? I am use to a unix-like path /blah/blah/blah. Would I need
    to change this to x:\blah\blah\bl ah where x = drive letter? What about
    creating fs objects? file works the same on both? os.walk works the same?

    Thanks for the advice!!!

  • BW Glitch

    #2
    Re: porting python script from linux to windows

    hokieghal99 wrote:
    [color=blue]
    > What are the specific steps that one should take to make a python script
    > that works on a Linux x86 machine also work on a Windows x86 machine?
    >
    > I am using os, re and string in the script. How do paths differ between
    > the two OSes? I am use to a unix-like path /blah/blah/blah. Would I need
    > to change this to x:\blah\blah\bl ah where x = drive letter? What about
    > creating fs objects? file works the same on both? os.walk works the same?[/color]

    Instead of using full paths, try using the os.path.join method. It makes
    it easier to port from/to any OS.

    --
    Glitch

    -----BEGIN TF FAN CODE BLOCK-----
    G+++ G1 G2+ BW++++ MW++ BM+ Rid+ Arm-- FR+ FW-
    #3 D+ ADA N++ W OQP MUSH- BC- CN++ OM P75
    -----END TF FAN CODE BLOCK-----

    "So you failed."
    "Absolutely !"
    "Completely ."
    -- Optimus Primal, Rattrap, and Airazor, "Before the Storm"

    Comment

    • Rene Pijlman

      #3
      Re: porting python script from linux to windows

      hokieghal99:[color=blue]
      >What are the specific steps that one should take to make a python script
      >that works on a Linux x86 machine also work on a Windows x86 machine?[/color]

      Check for platform dependencies in the documentation of all modules that
      you use.
      [color=blue]
      >I am using os, re and string in the script. How do paths differ between
      >the two OSes? I am use to a unix-like path /blah/blah/blah. Would I need
      >to change this to x:\blah\blah\bl ah where x = drive letter?[/color]

      I'm currently developing an app on Windows and testing it for production
      on Linux. I use os.path.join() to construct pathnames and have encountered
      no portability problems.
      [color=blue]
      >What about creating fs objects? file works the same on both?[/color]

      Yes. But note the advice about binary files in the documentation of the
      open()/file() builtin function.
      [color=blue]
      >os.walk works the same?[/color]

      It works :-)

      --
      René Pijlman

      Comment

      • Dan Bishop

        #4
        Re: porting python script from linux to windows

        hokieghal99 <hokiegal99@hot mail.com> wrote in message news:<brd5n1$jj 1$1@solaris.cc. vt.edu>...[color=blue]
        > What are the specific steps that one should take to make a python script
        > that works on a Linux x86 machine also work on a Windows x86 machine?
        >
        > I am using os, re and string in the script. How do paths differ between
        > the two OSes? I am use to a unix-like path /blah/blah/blah. Would I need
        > to change this to x:\blah\blah\bl ah where x = drive letter?[/color]

        You woudn't *need* to; the drive letter can be omitted when the file
        is on the same drive. Also, Windows doesn't care what kind of slashes
        you use (except for cmd.exe).

        But you will have to, for example, change "/home/dan" to
        "c:\\winnt\\Doc uments and Settings\\dan".
        [color=blue]
        > What about
        > creating fs objects? file works the same on both?[/color]

        For the most part, yes, but in mind that, on Windows, it matters
        whether you open a file in text or binary mode.
        [color=blue]
        > os.walk works the same?[/color]

        Yes.

        Comment

        • Hans Nowak

          #5
          Re: porting python script from linux to windows

          hokieghal99 wrote:[color=blue]
          > What are the specific steps that one should take to make a python script
          > that works on a Linux x86 machine also work on a Windows x86 machine?[/color]

          Run it, and see what happens. ;-) Seriously, in theory there is no reason why
          it shouldn't work right out of the box, unless you have platform-specific code.
          So I'd say, just run it and see if you encounter any problems.
          [color=blue]
          > I am using os, re and string in the script. How do paths differ between
          > the two OSes? I am use to a unix-like path /blah/blah/blah. Would I need
          > to change this to x:\blah\blah\bl ah where x = drive letter?[/color]

          Maybe. Paths with slashes can be used on Windows as well.
          [color=blue]
          > What about
          > creating fs objects? file works the same on both? os.walk works the same?[/color]

          Files should work the same, except that on Windows opening files in 'binary
          mode' is different from 'text mode'. os.walk should work just fine.

          HTH,

          --
          Hans (hans@zephyrfal con.org)
          Memimpin Angin Perubahan Teknologi




          Comment

          Working...