I am trying to write a string and a float into a file using:
t=['SDSS J2000']
data=[10]
astropy.io.ascii.write([t,data] ,'data.dat',names=['name','num'],formats={'name':'%s','num':'%f'})
the output file is:
name num
"SDSS J2000" 10.000000
how can I write the string to file without the quotes, like this:
SDSS J2000 10.000000
You provided 2 data and 2 values, so
astropy
quotes the data to be able to read it back.Do you really need
astropy
for this? Standard python does it easily usingstr.format
:if you really want to achieve that using
astropy
you can usequotechar
set to space (and use the option to avoid displaying header):this writes:
so too many spaces, expected when you try to twist the library's arm into writing data that cannot be read back reliably
EDIT: another way to do it is to let
astropy
write its quotes and remove them afterwards, usingio.StringIO
to avoid writing/reading/writing to disk:file now contains: