File-writing not working in Windows?

John Machin sjmachin at lexicon.net
Fri Jun 6 19:27:18 EDT 2008


On Jun 7, 1:18 am, tda... at gmail.com wrote:
> All,
>

[code snipped]

>
> 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.
>
> 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.)
>
> Can anyone tell me what it is that I'm missing which would prevent the
> file from being created on Windows natively?
>
> I'm sorry I can't provide any more of the code, and I know that that
> will hamper your efforts in helping me, so I apologise up front.
>
> Assumptions:
> You can assume self.checkbox25.GetValue() is always false for now, and
> self.Info[x][0] contains a two character string like "00" or "09" or
> "14".  There is always a match in the fileTarget, so self.Info[x][2]
> will always be true at some point, as will self.Info[x][4].  I am
> cutting an HTML file at predetermined comment sections, and I have
> control over the HTML files that are being cut.  (So I can force the
> file to match what I need it to match if necessary.)

Assume nothing. Don't believe anyone who says "always". Insert some
print statements and repr() calls to show what's actually there.

> I hope however that it's something obvious that a Python guru here
> will be able to spot and that this n00b is missing!

*IF* the problem is in the code, it would be easier to spot if you had
removed large chunks of indentation before posting.

Less is more: change "if (foo == 2):" to "if foo == 2:", "foo == True"
to "foo", and "foo == False" to "not foo".

Browse http://www.python.org/dev/peps/pep-0008/

HTH,
John



More information about the Python-list mailing list