File-writing not working in Windows?

tdahsu at gmail.com tdahsu at gmail.com
Fri Jun 6 14:22:07 EDT 2008


On Jun 6, 11:35 am, jay graves <jaywgra... at gmail.com> wrote:
> On Jun 6, 10:18 am, tda... at gmail.com wrote:
> <snippage>
>
> > This code works PERFECTLY in Linux.  Where I have a match in the file
> > I'm processing, it gets cut out from the start of the match until the
> > end of the match, and written to the temporary file in tempdir.
> > It does not work in Windows.  It does not create or write to the
> > temporary file AT ALL.  It creates the tempdir directory with no
> > problem.
>
> In general, I don't use string concatenation when building paths.
> Especially on scripts that are meant to run on multiple platforms.
>
> > Here's the kicker: it works perfectly in Windows if Windows is running
> > in VMware on a Linux host!  (I assume that that's because VMware is
> > passing some call to the host.)
>
> probably a red herring.
>
> > Can anyone tell me what it is that I'm missing which would prevent the
> > file from being created on Windows natively?
>
> Get rid of the 'posix' check and use os.path.join to create
> 'tempfileName' and see if it works.
>
> HTH.
> ...
> Jay Graves

Jay,

Thank you for your answer.  I have researched os.path.join.  I have
changed the code to read as follows:

if (self.checkbox25.GetValue() == False):
    initialFileName = self.Info[x][0] + "_tmp_" + fileName + ".txt"
    tempfileName = os.path.join("proctemp", initialFileName)
else:
    initialFileName = self.Info[x][0] + "_xyz.txt"
    tempfileName = os.path.join("proctemp", initialFileName)

this still works in Linux; it does not work in Windows.

I am thinking that the "g.open(tempFileName, 'a')" command is the
issue.  Is there anything different about opening a file in Windows?
Does Windows understand "append", or would I have to do control checks
for seeing if the file is created and then appending?



More information about the Python-list mailing list