[Tutor] Writing to file
Daniel Ehrenberg
littledanehren at yahoo.com
Mon Dec 8 17:43:28 EST 2003
Guillermo Fernandez wrote:
> hi,
>
> I'm trying to making Octave (later will be
> Matlab...) and one of my programs
> communicate together. For that, I create a file
> that's similar to the one that
> Octave creates to save his variables (with the
> 'save' command). This look like
> this:
> # Created by Octave 2.1.42, Mon Dec 08 18:57:00 2003
> RST <guille at Guille>
> # name: a
> # type: matrix
> # rows: 2
> # columns: 2
> 1 2
> 3 4
>
> I did the program and the file is correctly created.
> Still, while loading my
> file, I've got this error:
> octave:1> load wireless
> ' found in file `wireless'ier `daysmac
>
> I'm almost sure the difference between the files he
> creates and I create is the
> following:
> $ file wireless
> wireless: ASCII text, with CRLF line terminators
> $ file save
> save: ASCII text
>
> I don't really get what's those CRLF line
> terminators (maybe the '\r\n' of
> windows?) but I would apreciate to get rid of them
> to have standard ASCII file
> And as the newlines attribute of a file is not
> writable, I can not set it to
> '\n' (seems to be set to None for the moment).
>
> Hereafter is my code.
>
> Thanks,
>
> Guille
Just open the file in binary mode. This is done by
putting 'b' in the string that determines the mode of
the file. For example, you opened the file with mode
'w'. If you want to open it in binary mode, just use
'wb' instead. This basically makes it so that Python
writes directly to the file without doing its fancy
cross-platform stuff. It can also be used for reading
files (in mode 'rb').
Daniel Ehrenberg
__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/
More information about the Tutor
mailing list