473,327 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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\blah where x = drive letter? What about
creating fs objects? file works the same on both? os.walk works the same?

Thanks for the advice!!!

Jul 18 '05 #1
4 2684
hokieghal99 wrote:
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\blah where x = drive letter? What about
creating fs objects? file works the same on both? os.walk works the same?


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"

Jul 18 '05 #2
hokieghal99:
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?
Check for platform dependencies in the documentation of all modules that
you use.
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\blah where x = drive letter?
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.
What about creating fs objects? file works the same on both?
Yes. But note the advice about binary files in the documentation of the
open()/file() builtin function.
os.walk works the same?


It works :-)

--
René Pijlman
Jul 18 '05 #3
hokieghal99 <ho********@hotmail.com> wrote in message news:<br**********@solaris.cc.vt.edu>...
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\blah where x = drive letter?
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\\Documents and Settings\\dan".
What about
creating fs objects? file works the same on both?
For the most part, yes, but in mind that, on Windows, it matters
whether you open a file in text or binary mode.
os.walk works the same?


Yes.
Jul 18 '05 #4
hokieghal99 wrote:
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?
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.
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\blah where x = drive letter?
Maybe. Paths with slashes can be used on Windows as well.
What about
creating fs objects? file works the same on both? os.walk works the same?


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 (ha**@zephyrfalcon.org)
http://zephyrfalcon.org/

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ben Finney | last post by:
Howdy all, I'm experimenting with carrying my personal computing environment around on a keychain USB flash storage device. I have the usual suspects on there: SSH keys, GPG keys, program...
2
by: jacques | last post by:
hello everybody i have a computer with redhat linux. on this computer i have some python scripts i want to run. i don't want to run them with linux but with windows. so i have a second computer...
13
by: Darren Dale | last post by:
Some time ago I asked about executing a python program or script. For windows, I was informed that the .py extension could be added to some list of executable extensions, and then I could just type...
1
by: Sunanda | last post by:
Hi, I am a newbie to .Net. I have an application in running in linux, a set of .c and .h files. I also have a makefile in linux to create the executable. I want to port this to windows...
3
by: diffuser78 | last post by:
I am a newbie in Python and want your help in writing python script. I have to remotely shut the windows px from linux box. I run OpenSSH on windows PC. I remotely connect it from Linux box using...
15
by: kyosohma | last post by:
Hi, I am trying to get a small group of volunteers together to create Windows binaries for any Python extension developer that needs them, much like the package/extension builders who volunteer...
19
by: Dotan Cohen | last post by:
I often see mention of SMBs that either want to upgrade their Windows installations, or move to Linux, but cannot because of inhouse VB apps. Are there any Python experts who I can reference them...
0
by: Ed Leafe | last post by:
On Oct 18, 2008, at 8:12 AM, Dotan Cohen wrote: Sorry for the delay in responding, but someone just pointed out this post to me. You might want to take a look at Dabo, which is an integrated...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.