Stupid Cooking Tricks on Windows.

Tue 14 February 2006

Filed under OS

Tags Lamer Moments Python

I have used Python to do many things. However, I was debugging some code for a friend and we had the strangest side effect. We were using PyCURL to read a file from a webserver, and save it to disk as part of a wxPython app that he is writing. The whole app works perfectly on Linux, but on Windows it was crashing.

Cliff tried a number of things, but he has had occasional issues w/ file writes under VMware (Which is where he runs Windows). He suspected he was hitting a write issue due to VMware, and had hit a dead end solving the problem.

I finally had an opportunity to review the problem, and I stumbled across the solution while reading the pycurl multi-file retriever. It turns out that on sane platforms (e.g. Linux) the python file object defaults to binary files. Under uber-magical windows, the file object defaults to ASCII. What a suprise. The entire problem of cooked zip files was solved by:

file('foo.zip','wb').write(data.getvalue())

Woo-hoo.


Tech Notes:

  • 'data' is a StringIO object.
  • We are using standard crap w/ pycurl.

Comments


Up To Something © Joshua M Schmidlkofer Powered by Pelican and Twitter Bootstrap. Icons by Font Awesome and Font Awesome More