On 7/17/2010 9:01 AM, Mark Lawrence wrote:
[snip]
As an alternative to the suggestions given so far, why not open the
file for write in binary mode, i.e. use 'wb' instead of 'w', and don't
bother converting to strings? Then when reading the file use 'rb'
instead of 'r'.
You can only write strings to files. See 6.9 in the documentation:
file.write(/str/)
Write a string to the file
b mode only affects how line ends are handled. See 2. Built-in Functions:
The default is to use text mode, which may convert '\n' characters to a
platform-specific representation on writing and back on reading. Thus,
when opening a binary file, you should append 'b' to the /mode/ value to
open the file in binary mode, which will improve portability. (Appending
'b' is useful even on systems that don't treat binary and text files
differently, where it serves as documentation.)
--
Bob Gailer
919-636-4239
Chapel Hill NC
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor