Hello,
as said in the subject, the following code produces an error. Is it normal ?
********************************************************** A = r_[1] file_buffer = StringIO() A.tofile(file_buffer)
IOError: first argument must be a string or open file **********************************************************
On 25.09.2011 18:23, OC wrote:
as said in the subject, the following code produces an error. Is it normal ?
A = r_[1] file_buffer = StringIO() A.tofile(file_buffer)
IOError: first argument must be a string or open file
Yes, this is a known shortcoming of .tofile().
On 25.09.2011 18:23, OC wrote:
as said in the subject, the following code produces an error. Is it normal ?
A = r_[1] file_buffer = StringIO() A.tofile(file_buffer)
IOError: first argument must be a string or open file
if you want to write to a string, why not use .tostring()?
-CHB
if you want to write to a string, why not use .tostring()?
Because A.tostring() returns the binary data, while I would like the text representation. More precisely, I would like to use A.tofile(sep="\t").
Yes, this is a known shortcoming of .tofile().
Is it worth filing a bug report ?
On 9/27/11 2:14 AM, oc-spam66 wrote:
if you want to write to a string, why not use .tostring()?
Because A.tostring() returns the binary data, while I would like the text representation. More precisely, I would like to use A.tofile(sep="\t").
I see -- I've always thought mingling binary and text reading and writing was an API mistake.
Ah, I found a workaround: savetxt() can work with a StringIO -> savetxt(file_buffer, A)
This is only a workaround. I still think A.tofile() should be capable of writing into a StringIO.
or .tostring() should support text (but that's what savetxt is for)
Anyway, the text behavior of fromfile() and tofile() is broken in many ways -- it really need a major refactor,and yes,this is one issue that it would be nice to address. Or just get deprecate the text functionality.
-Chris
Ah, I found a workaround: savetxt() can work with a StringIO -> savetxt(file_buffer, A)
This is only a workaround. I still think A.tofile() should be capable of writing into a StringIO.